当前位置: 首页>>代码示例>>C#>>正文


C# SessionFactory.Delete方法代码示例

本文整理汇总了C#中SessionFactory.Delete方法的典型用法代码示例。如果您正苦于以下问题:C# SessionFactory.Delete方法的具体用法?C# SessionFactory.Delete怎么用?C# SessionFactory.Delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SessionFactory的用法示例。


在下文中一共展示了SessionFactory.Delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Delete

        public ActionResult Delete(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashWarn("请选择要删除的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var models = session.Find<TrainNotice>(m => m.Id.In(ids));
                if (models.Count == 0)
                {
                    FlashInfo("你没有选择任何可以删除的培训通知。");
                    return Close();
                }
                var notices = string.Join(", ", models.Select(m => m.Title));

                if (models.Any(model => !session.Delete(model)))
                {
                    session.Rollback();
                    FlashError("删除培训通知{0}失败!", notices);
                    return View(models);
                }
                session.Commit();

                FlashSuccess("删除培训通知{0}成功!", notices);
                return Close();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:30,代码来源:TrainNoticeController.cs

示例2: ClearActionLog

 public ActionResult ClearActionLog(FormCollection collection)
 {
     using (var session = new SessionFactory().OpenSession())
     {
         var dt = DateTime.Now.AddDays(-30);
         session.Delete<ActionLog>(m => m.CreatedAt < dt);
         FlashSuccess("清理日志成功!");
         return RedirectToAction("Index");
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:10,代码来源:AdminController.cs

示例3: Delete

 public ActionResult Delete(FormCollection collection, long[] ids)
 {
     if (ids.Length == 0)
     {
         FlashWarn("请选择要删除的记录。");
         return Close();
     }
     using (var session = new SessionFactory().OpenSession())
     {
         session.BeginTransaction();
         var models = session.Find<Role>(m => m.Id.In(ids));
         if (models == null || models.Count == 0)
         {
             FlashFailure("你要删除的角色不存在或者已被删除!");
             return Close();
         }
         if (models.Any((m => "SYSTEM".Equals(m.CreatedBy))))
         {
             FlashFailure("你要删除的角色包含系统内置角色,无法删除!");
             return Close();
         }
         var roleIds = models.Select(n => n.Id).ToArray();
         if (session.Delete(models) &&
             session.Delete<NavigationPriviledge>(m => m.Flag.Equals(NavigationPriviledge.RoleType) && m.OwnerId.In(roleIds)) &&
             session.Delete<AccountNavigationRef>(m => m.Type.Equals(AccountNavigationRef.RoleType) && m.OwnerId.In(roleIds)))
         {
             session.Commit();
             FlashInfo("角色删除成功");
             return Close();
         }
         session.Rollback();
         FlashError("角色删除失败!");
         return View();
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:35,代码来源:RoleController.cs

示例4: User

        public new ActionResult User(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashInfo("请选择要查看用户的角色。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var roles = session.Find<Role>(m => m.Id.In(ids));
                if (roles == null || roles.Count == 0)
                {
                    FlashInfo("请选择要查看用户的角色。");
                    return Close();
                }
                ViewData["roleName"] = string.Join(",", roles.Select(m => m.Name));

                var roleIds = roles.Select(m => m.Id).ToList();
                var userIds = Request.Params["select_id"].ToLongArray();

                session.Delete<AccountRoleRef>(m => m.RoleId.In(ids));
                if (userIds.Length > 0)
                {
                    var q = new Criteria<Account>(session)
                        .AndIn<User>(m => m.Name, n => n.Code, n => n.Id.In(userIds))
                        .Select(m => m.Id);
                    var accountIds = q.To<long>();

                    if (accountIds.Count < userIds.Length)
                    {
                        FlashWarn("有{0}个用户没有激活,请全部激活后再操作。", userIds.Length - accountIds.Count);
                        return Close();
                    }

                    var toCreateItems = (from accountId in accountIds
                                         from roleId in roleIds
                                         select
                                             new AccountRoleRef
                                                 {
                                                     AccountId = accountId,
                                                     RoleId = roleId,
                                                     CreatedAt = DateTime.Now,
                                                     CreatedBy = CurrentAccountNo
                                                 }).ToArray();
                    if (toCreateItems.Length > 0)
                    {
                        if (session.Create(toCreateItems))
                        {
                            session.Commit();
                            FlashSuccess("给角色分配用户成功!");
                            return Close();
                        }
                    }
                    session.Rollback();
                    FlashFailure("给角色分配用户失败!");
                    return User(ids);
                }
                session.Commit();
                FlashSuccess("取消角色全部用户成功!");
                return Close();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:63,代码来源:RoleController.cs

示例5: Pintask

        public ActionResult Pintask(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashInfo("请选择要查看用户的角色。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                var roles = session.Find<Role>(m => m.Id.In(ids));
                if (roles == null || roles.Count == 0)
                {
                    FlashInfo("请选择要查看用户的角色。");
                    return Close();
                }
                ViewData["roleName"] = string.Join(",", roles.Select(m => m.Name));

                var roleIds = roles.Select(m => m.Id).ToList();
                var navIds = Request.Params["select_id"].ToLongArray();

                session.Delete<AccountNavigationRef>(m => m.Type.Equals(NavigationPriviledge.RoleType) && m.OwnerId.In(ids));

                var toCreateItems = (from navId in navIds
                                     from roleId in roleIds
                                     select new AccountNavigationRef { OwnerId = roleId, NavigationId = navId, Type = AccountNavigationRef.RoleType, CreatedAt = DateTime.Now, CreatedBy = CurrentAccountNo }).ToArray();
                if (toCreateItems.Length > 0)
                {
                    if (session.Create(toCreateItems))
                    {
                        FlashSuccess("给角色设置常用功能成功!");
                        return Close();
                    }
                }
                FlashFailure("给角色设置常用功能失败!");
                return Pintask(ids);
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:37,代码来源:RoleController.cs

示例6: Delete

        public ActionResult Delete(FormCollection collection, long[] ids, long id = 0)
        {
            if (ids.Length == 0)
            {
                FlashWarn("请选择要删除的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var models = session.Find<PunishmentDossierFiles>(m => m.Id.In(ids));
                if (models.Count == 0)
                {
                    FlashInfo("你没有选择任何可以删除的记录。");
                    return Close();
                }
                if (models.Any(m => !m.CreatedBy.Equals(CurrentAccountNo)))
                {
                    FlashInfo("你不是创建人,不能删除{0}", string.Join(",", models.Where(m => !m.CreatedBy.Equals(CurrentAccountNo)).Select(m => m.FileName)));
                    return Close();
                }
                var contract = session.Load<PunishmentDossier>(id);
                if (contract == null)
                {
                    FlashWarn("材料未找到,请联系管理员!");
                    return Close();
                }
                if (!IsEditAble(contract))
                {
                    FlashInfo("材料已经提交,相关文件不能删除!");
                    return Close();
                }
                var displays = string.Join(", ", models.Select(m => m.FileName));

                if (models.Any(model => !model.DeleteFile()) || !session.Delete(models))
                {
                    session.Rollback();
                    FlashError("删除记录{0}失败!", displays);
                    return View(models);
                }
                session.Commit();

                FlashSuccess("删除记录{0}成功!", displays);
                return Close();

            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:47,代码来源:PunishmentDossierFilesController.cs

示例7: Delete

        public ActionResult Delete(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashWarn("请选择要删除的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var models = session.Find<TrainManagement>(m => m.Id.In(ids));
                if (models.Count == 0)
                {
                    FlashInfo("你没有选择任何可以删除的记录。");
                    return Close();
                }
                var displays = string.Join(", ", models.Select(m => string.Concat(m.Id)));

                if (session.Delete<TrainManagement>(m => m.Id.In(ids)))
                {
                    session.Commit();
                    FlashSuccess("删除记录{0}成功!", displays);
                    return Close();
                }
                session.Rollback();
                FlashError("删除记录{0}失败!", displays);
                return View(models);

            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:30,代码来源:TrainManagementController.cs

示例8: Delete

        public ActionResult Delete(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashWarn("请选择要删除的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var models = session.Find<StandardFile>(m => m.Id.In(ids));
                if (models.Count == 0)
                {
                    FlashInfo("你没有选择任何可以删除的记录。");
                    return Close();
                }
                if (models.Any(m => !m.CreatedBy.Equals(CurrentAccountNo)))
                {
                    FlashInfo("你不是创建人,不能删除{0}", string.Join(",", models.Where(m => !m.CreatedBy.Equals(CurrentAccountNo)).Select(m => m.FileName)));
                    return Close();
                }

                var displays = string.Join(", ", models.Select(m => m.FileName));

                if (models.Any(model => !model.DeleteFile()) || !session.Delete(models))
                {
                    session.Rollback();
                    FlashError("删除记录{0}失败!", displays);
                    return View(models);
                }
                session.Commit();

                FlashSuccess("删除记录{0}成功!", displays);
                return Close();

            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:37,代码来源:InstitutionManagementController.cs

示例9: Delete

        public ActionResult Delete(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashWarn("请选择要删除的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var models = session.Find<TrainNeed>(m => m.Id.In(ids));
                if (models.Count == 0)
                {
                    FlashInfo("你没有选择任何可以删除的记录。");
                    return Close();
                }
                if (!models.All(m => m.Type.Equals(TrainNeedType.部门)))
                {
                    FlashInfo("只能删除类型为\"部门\"的记录!");
                    return Close();
                }
                if (!models.All(CanSubmit))
                {
                    FlashInfo("所选记录包含已提交记录!");
                    return Close();
                }
                var displays = string.Join(", ", models.Select(m => string.Concat(m.Id)));

                if (session.Delete<TrainNeed>(m => m.Id.In(ids)))
                {
                    session.Commit();
                    FlashSuccess("删除记录{0}成功!", displays);
                    return Close();
                }
                session.Rollback();
                FlashError("删除记录{0}失败!", displays);
                return View(models);

            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:40,代码来源:TrainNeedDepartmentController.cs

示例10: Delete

        public ActionResult Delete(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashWarn("请选择要删除的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var models = session.Find<User>(m => m.Id.In(ids) && !m.IsActive);
                var rootModel = models.FirstOrDefault(m => m.Code.Equals("root"));
                if (rootModel != null)
                {
                    FlashWarn("你不能删除ROOT账户。");
                    models.Remove(rootModel);
                }
                if (models.Count == 0)
                {
                    FlashInfo("你没有选择任何可以删除的用户。为了系统安全考虑,已禁用的账户才能被删除。");
                    return Close();
                }
                var users = string.Join(", ", models.Select(m => m.Name));

                foreach (var model in models)
                {
                    if (!session.Delete(model) || !session.Delete<Account>(m => m.Name.Equals(model.Code)))
                    {
                        session.Rollback();
                        FlashError("删除用户{0}失败!", users);
                        return Delete(ids);
                    }
                }
                session.Commit();

                UserActivity.UserNameIdMapHolder.Reset();

                FlashSuccess("删除用户{0}成功!", users);
                return Close();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:41,代码来源:UserController.cs

示例11: Delete

        public ActionResult Delete(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashWarn("请选择要删除的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var models = session.Find<InstitutionManagement>(m => m.Id.In(ids));
                if (models.Count == 0)
                {
                    FlashInfo("你没有选择任何可以删除的记录。");
                    return Close();
                }
                var displays = string.Join(", ", models.Select(m => m.Id));
                var fileIds = models.Select(m => m.Id).ToArray();
                var files = session.Find<UploadFile>(m => m.Id.In(fileIds));
                //删除上传的文件
                foreach (var uploadFile in files)
                {
                    uploadFile.DeleteFile();
                }

                if (models.Any(model => !session.Delete(model)) || files.Any(m => !session.Delete(m)))
                {
                    session.Rollback();
                    FlashError("删除记录{0}失败!", displays);
                    return View(models);
                }
                session.Commit();

                FlashSuccess("删除记录{0}成功!", displays);
                return Close();

            }
        }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:38,代码来源:InstitutionManagementController.cs

示例12: Edit

 public ActionResult Edit(FormCollection collection, long[] ids)
 {
     if (ids.Length == 0)
     {
         FlashWarn("请选择要修改的记录。");
         return Close();
     }
     using (var session = new SessionFactory().OpenSession())
     {
         var model = session.Load<Exam>(m => m.Id.In(ids));
         if (model == null)
         {
             FlashInfo("你没有选择任何可以修改的记录。");
             return Close();
         }
         TryUpdateModel(model, collection.ToValueProvider());
         if (!ModelState.IsValid)
         {
             return View(model);
         }
         model.UpdatedAt = DateTime.Now;
         model.UpdatedBy = CurrentAccountNo;
         session.Delete<Question>(m => m.ExamId == model.Id);
         if (session.Update(model) && CreatQuestions(model, session))
         {
             FlashSuccess("记录修改成功");
             return Close();
         }
         return View(model);
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:31,代码来源:ExamController.cs

示例13: Delete

        public ActionResult Delete(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashWarn("请选择要删除的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();

                var orgs = session.Find<SchoolDepartment>();
                var topItems = orgs.Where(m => m.Id.In(ids)).ToList();
                var toDelItems = new List<SchoolDepartment>();
                foreach (var topItem in topItems)
                {
                    toDelItems.AddRange(topItem.GetDescentdant(orgs, true));
                }
                var users = session.Find<User>(m => m.DepartmentId.In(ids));
                var u = new List<User>();
                foreach (var user in users)
                {
                    user.DepartmentId = 0;
                    u.Add(user);
                }
                //删除下级部门&&将该部门下的用户SchoolDepartmentId设为0

                if (toDelItems.Count > 0 && !session.Delete(toDelItems))
                {
                    session.Rollback();
                    FlashError("删除部门失败!");
                    return View(topItems);
                }
                if (u.Count > 0 && !session.Update(u))
                {
                    session.Rollback();
                    FlashError("删除部门后更新用户信息失败!");
                    return View(topItems);
                }
                var roles = session.Find<Role>(m => m.DepartmentId.In(ids));
                if (!session.Delete<Role>(m => m.DepartmentId.In(ids)))
                {
                    session.Rollback();
                    FlashError("删除部门角色失败!");
                    return View(topItems);
                }
                var roleIds = roles.Select(m => m.Id).ToArray();
                if (roleIds.Length > 0)
                {
                    if (!session.Delete<AccountRoleRef>(m => m.RoleId.In(roleIds)))
                    {
                        session.Rollback();
                        FlashError("删除部门所属角色和用户的对应关系失败!");
                        return View(topItems);
                    }
                }
                session.Commit();
                ViewData.Model = toDelItems;
                FlashSuccess(" 部门删除成功 ");
                return Close();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:62,代码来源:SchoolDepartmentController.cs

示例14: RemoveNavigation

        public ActionResult RemoveNavigation()
        {
            string url = Request.Params["nav"];
            string handleId = Request.Params["handleId"];

            try
            {
                CurrentAccountId = UserActivity.UserNameIdMapHolder.GetId(CurrentAccountNo);
            }
            catch (Exception e)
            {
                Log.Error("系统获取用户ID失败,错误信息:{0}", e.Message);
            }

            using (var session = new SessionFactory().OpenSession())
            {
                const string sql = "SELECT id FROM `navigations` WHERE `url` = '{0}'";
                var exceptId = session.ExecuteScalar<string>(string.Format(sql, url.Replace("'", "''"))).TryToLong();
                if (
                    session.Delete<AccountNavigationRef>(
                        m => m.Type.Equals(2) && m.OwnerId.Equals(CurrentAccountId) && m.NavigationId.Equals(exceptId)))
                {
                    return JsonDataResult(new { status = 200, message = "删除成功!", handleId });
                }
                return JsonDataResult(new { status = 100, message = "操作失败!", handleId });
            }
        }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:27,代码来源:ProfileController.cs

示例15: Delete

        public ActionResult Delete(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashWarn("请选择要删除的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var models = session.Find<SchoolSection>(m => m.Id.In(ids));
                if (models.Count == 0)
                {
                    FlashInfo("你没有选择任何可以删除的校区。");
                    return Close();
                }
                var schoolSections = string.Join(", ", models.Select(m => m.Name));

                foreach (var model in models)
                {
                    if (!session.Delete(model))
                    {
                        session.Rollback();
                        FlashError("删除校区{0}失败!", schoolSections);
                        return View(models);
                    }
                }
                session.Commit();

                FlashSuccess("删除校区{0}成功!", schoolSections);
                return Close();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:33,代码来源:SchoolSectionController.cs


注:本文中的SessionFactory.Delete方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。