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


C# SessionFactory.Rollback方法代码示例

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


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

示例1: Active

 public ActionResult Active(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);
         if (models.Count == 0)
         {
             FlashInfo("你没有选择任何需要激活的用户。");
             return Close();
         }
         foreach (User model in models)
         {
             if (!model.Active(session, CurrentAccountNo))
             {
                 session.Rollback();
                 FlashError("账户激活失败!");
                 return Close();
             }
         }
         session.Commit();
         FlashSuccess("账户激活成功");
         return Close();
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:30,代码来源:UserController.cs

示例2: Create

 public ActionResult Create(FormCollection collection, long id = 0)
 {
     var model = new TrainManagementItem { TrainManId = id };
     TryUpdateModel(model, collection.ToValueProvider());
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     using (var session = new SessionFactory().OpenSession())
     {
         session.BeginTransaction();
         var trainMan = session.Load<TrainManagement>(id);
         if (trainMan == null)
         {
             FlashError("培训不存在,请联系管理员!");
             return Close();
         }
         model.Year = trainMan.Year;
         model.TrainManName = trainMan.Name;
         model.CreatedAt = DateTime.Now;
         model.CreatedBy = CurrentAccountNo;
         ViewData.Model = model;
         if (session.Create(model))
         {
             session.Commit();
             FlashSuccess("创建记录成功!");
             return Close();
         }
         session.Rollback();
         FlashFailure("创建记录失败!");
         return View();
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:33,代码来源:TrainManagementItemController.cs

示例3: Create

        public ActionResult Create(FormCollection collection)
        {
            var model = new SchoolSection();
            TryUpdateModel(model, collection.ToValueProvider());
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                if (session.Load<SchoolSection>(m => m.Name.Equals(model.Name)) != null)
                {
                    FlashWarn("校区{0}已经存在,创建失败。", model.Name);
                    return View(model);
                }
                model.CreatedAt = DateTime.Now;
                model.CreatedBy = CurrentAccountNo;
                ViewData.Model = model;

                if (session.Create(model))
                {
                    session.Commit();
                    FlashSuccess("创建校区[{0}]成功!", model.Name);
                    return Close();
                }
                session.Rollback();
                FlashFailure("创建校区[{0}]失败!", model.Name);
                return View();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:31,代码来源:SchoolSectionController.cs

示例4: 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

示例5: Create

 public ActionResult Create(FormCollection collection)
 {
     var model = new TrainManagement();
     TryUpdateModel(model, collection.ToValueProvider());
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     using (var session = new SessionFactory().OpenSession())
     {
         session.BeginTransaction();
         model.CreatedAt = DateTime.Now;
         model.CreatedBy = CurrentAccountNo;
         ViewData.Model = model;
         if (session.Create(model))
         {
             session.Commit();
             FlashSuccess("创建记录成功!");
             return Close();
         }
         session.Rollback();
         FlashFailure("创建记录失败!");
         return View();
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:25,代码来源:TrainManagementController.cs

示例6: Approve

        public ActionResult Approve(FormCollection collection, long[] ids)
        {
            if (ids == null || ids.Length == 0)
            {
                FlashWarn("请选择要审核的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var model = session.Load<PunishmentDossier>(m => m.Id.In(ids));
                if (model == null)
                {
                    FlashInfo("你没有选择任何可以审核的记录。");
                    session.Rollback();
                    return Close();
                }
                if (!CanApprove(model))
                {
                    FlashWarn("无法审核,请检查所选记录状态!");
                    session.Rollback();
                    return Close();
                }
                TryUpdateModel(model, collection.ToValueProvider());
                if (!ModelState.IsValid)
                {
                    return View("Edit", model);
                }
                model.ApproveState = ApproveStateConst.已审核;
                model.ApprovePerson3 = CurrentAccountNo.GetName();
                model.UpdatedAt = DateTime.Now;
                model.UpdatedBy = CurrentAccountNo;

                if (session.Update(model))
                {
                    FlashSuccess("记录审核成功");
                    session.Commit();
                    return Close();
                }
                FlashFailure("审核失败,请联系管理员!");
                session.Rollback();
                return Close();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:44,代码来源:PunishmentDossierLawController.cs

示例7: Approve

        public ActionResult Approve(FormCollection collection, long[] ids)
        {
            if (ids == null || ids.Length == 0)
            {
                FlashWarn("请选择要审核的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var models = session.Find<Contract>(m => m.Id.In(ids));
                if (models.Count == 0)
                {
                    FlashInfo("你没有选择任何可以审核的记录。");
                    session.Rollback();
                    return Close();
                }
                if (models.Any(m => !CanApprove(m)))
                {
                    FlashWarn("无法审核,请检查所选记录状态!");
                    session.Rollback();
                    return Close();
                }
                foreach (var model in models)
                {
                    model.State = ContractStateConst.承办部门审核;
                    model.ApproveState = ApproveStateConst.已审核;
                    model.ApprovePerson1 = CurrentAccountNo.GetName();
                    model.UpdatedAt = DateTime.Now;
                    model.UpdatedBy = CurrentAccountNo;
                }

                if (session.Update(models))
                {
                    FlashSuccess("记录审核成功");
                    session.Commit();
                    return Close();
                }
                FlashFailure("审核失败,请联系管理员!");
                session.Rollback();
                return Close();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:43,代码来源:ContractUndertakeController.cs

示例8: Create

        public ActionResult Create(FormCollection collection)
        {
            var model = new TrainNeed();
            TryUpdateModel(model, collection.ToValueProvider());
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            using (var session = new SessionFactory().OpenSession())
            {

                session.BeginTransaction();
                var models = session.Find<TrainNeed>(m =>
                        !m.IsCollected && m.Status.Equals(TrainNeedStatus.已提交培训部门) && m.Type.Equals(TrainNeedType.部门));
                if (models == null || !models.Any())
                {
                    FlashWarn("没有未汇总的需求!");
                    return Close();
                }
                foreach (var trainNeed in models)
                {
                    trainNeed.IsCollected = true;
                }
                model.IsCollected = false;
                model.CreatedAt = DateTime.Now;
                model.CreatedBy = CurrentAccountNo;
                model.Type = TrainNeedType.公司;
                ViewData["StaffNeeds"] = models;
                ViewData.Model = model;
                var exist = session.Load<TrainNeed>(m => m.Type.Equals(TrainNeedType.公司) && m.Year.Equals(model.Year));
                if (exist != null)
                {
                    ModelState.AddModelError("Year", "该年度公司培训需求已经存在!");
                    return View(model);
                }
                if (session.Create(model) && session.Update(models))
                {
                    session.Commit();
                    FlashSuccess("创建记录成功!");
                    return Close();
                }
                session.Rollback();
                FlashFailure("创建记录失败!");
                return View();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:46,代码来源:TrainNeedCompanyController.cs

示例9: Create

        public ActionResult Create(FormCollection collection)
        {
            var model = new InstitutionManagement { UploadPerson = CurrentAccountNo.GetName() };
            TryUpdateModel(model, collection.ToValueProvider());
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            using (var session = new SessionFactory().OpenSession())
            {
                for (var i = 0; i < Request.Files.Count; i++)
                {
                    // 检查文件后缀名
                    var file = Request.Files[i];
                    if (file == null || file.ContentLength <= 0) continue;

                    var ext = Path.GetExtension(file.FileName);
                    if (string.IsNullOrEmpty(ext) || (!ext.Equals(".doc") && !ext.Equals(".docx")))
                    {
                        FlashFailure("文件 '{0}' 后缀名不符合要求 (doc,docx)", file.FileName);
                        return View();
                    }
                    var uppath = Server.MapPath("~/upload/");
                    var item = new UploadFile();
                    item.SaveFile(file, uppath, CurrentAccountNo);
                    item.CreateHtml();
                    model.FileId = item.Id;
                    model.FileName = file.FileName;

                }

                session.BeginTransaction();
                model.CreatedAt = DateTime.Now;
                model.CreatedBy = CurrentAccountNo;
                ViewData.Model = model;
                if (session.Create(model))
                {
                    session.Commit();
                    FlashSuccess("创建记录成功!");
                    return Close();
                }
                session.Rollback();
                FlashFailure("创建记录失败!");
                return View();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:46,代码来源:InstitutionManagementController.cs

示例10: Approve

        public ActionResult Approve(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.All(CanApprove))
                {
                    FlashInfo("所选文件状态有误,请检查!");
                    return Close();
                }
                var displays = string.Join(", ", models.Select(m => m.FileName));

                foreach (var model in models)
                {
                    model.ApproveState = ApproveStateConst.已审核;
                    model.UpdatedAt = DateTime.Now;
                    model.UpdatedBy = CurrentAccountNo;
                }
                if (!session.Update(models))
                {
                    session.Rollback();
                    FlashError("审核记录{0}失败!", displays);
                    return View(models);
                }
                session.Commit();
                FlashSuccess("审核记录{0}成功!", displays);
                return Close();

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

示例11: Create

        public ActionResult Create(FormCollection collection)
        {
            var model = new TrainNeed();
            TryUpdateModel(model, collection.ToValueProvider());
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();

                model.StaffCode = CurrentAccountNo;
                model.StaffName = CurrentAccountNo.GetName();
                var dept = new Criteria<Department>(session)
                   .AndIn<User>(m => m.Id, n => n.DepartmentId, m => m.Code.Equals(CurrentAccountNo)).Load();
                model.DeptId = dept != null ? dept.Id : 0;
                model.Dept = dept != null ? dept.Name : null;
                model.IsCollected = false;
                model.CreatedAt = DateTime.Now;
                model.CreatedBy = CurrentAccountNo;
                model.Type = TrainNeedType.员工;
                model.Status = "";
                var exist = session.Load<TrainNeed>(m => m.Type.Equals(TrainNeedType.员工) && m.DeptId.Equals(model.DeptId) && m.Year.Equals(model.Year) && m.StaffCode.Equals(CurrentAccountNo));
                if (exist != null)
                {
                    ModelState.AddModelError("Year", "您该年度需求已经存在!");
                    return View(model);
                }
                ViewData.Model = model;
                if (session.Create(model))
                {
                    session.Commit();
                    FlashSuccess("创建记录成功!");
                    return Close();
                }
                session.Rollback();
                FlashFailure("创建记录失败!");
                return View();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:41,代码来源:TrainNeedController.cs

示例12: Approve

        public ActionResult Approve(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashWarn("请选择要审核的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var models = session.Find<TrainExperience>(m => m.Id.In(ids));
                if (models.Count == 0)
                {
                    FlashInfo("你没有选择任何可以审核的记录。");
                    return Close();
                }
                if (!models.All(CanApprove))
                {
                    FlashWarn("所选记录不能审核,请检查记录状态!");
                    return Close();
                }
                foreach (var item in models)
                {
                    item.ApproveStatus = ApproveStateConst.已审核;
                    item.UpdatedAt = DateTime.Now;
                    item.UpdatedBy = CurrentAccountNo;
                }

                if (session.Update(models))
                {
                    session.Commit();
                    FlashSuccess("审核成功");
                    return Close();
                }
                session.Rollback();
                FlashError("审核失败,请联系管理员!");
                return Close();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:39,代码来源:TrainExperienceDeptController.cs

示例13: Create

 public ActionResult Create(FormCollection collection)
 {
     var view = new TrainExperienceView();
     TryUpdateModel(view, collection.ToValueProvider());
     if (!ModelState.IsValid)
     {
         return View(view);
     }
     using (var session = new SessionFactory().OpenSession())
     {
         session.BeginTransaction();
         var model = new TrainExperience
         {
             CreatedAt = DateTime.Now,
             CreatedBy = CurrentAccountNo,
             TrainManItemId = view.TrainManItemId,
             Experience = view.Experience,
             Status = "",
             ApproveStatus = ""
         };
         if (null != session.Load<TrainExperience>(m => m.TrainManItemId.Equals(model.TrainManItemId)))
         {
             ModelState.AddModelError("TrainManName", "该培训心得已经存在!");
             return View(view);
         }
         ViewData.Model = view;
         if (session.Create(model))
         {
             session.Commit();
             FlashSuccess("创建记录成功!");
             return Close();
         }
         session.Rollback();
         FlashFailure("创建记录失败!");
         return View();
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:37,代码来源:TrainExperienceController.cs

示例14: ResetNavigation

        /// <summary>
        /// 重置导航
        /// </summary>
        /// <returns></returns>
        internal static bool ResetNavigation(string navigationContainerFilePath)
        {
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();
                var act = new SystemActivity();
                try
                {
                    // 准备工作1:备份原导航名(用于恢复授权)
                    act.BackupNavNames(session);

                    // 准备工作2:清空原导航
                    act.TruncateNavigation(session);

                    // 准备工作3:注册顶级导航分类
                    var container = act.RegisterNavigationContainer(session, navigationContainerFilePath);

                    // 注册导航
                    act.RegisterNavigation(session, container);

                    // 后置工作1:给root账户授权
                    if (!AssignPriviledgeToRoot(session))
                    {
                        throw new Exception("授权给root账户失败");
                    }

                    // 后置工作2:清理授权表中不存在的导航
                    act.CleanNavigationPriviledge(session);

                    // 后置工作3:清理账户授权表中不存在的导航
                    act.CleanAccountNavigationRef(session);

                    session.Commit();
                    return true;
                }
                catch (Exception e)
                {
                    session.Rollback();
                    act._logger.Error(e.Message);
                    return false;
                }
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:47,代码来源:SystemActivity.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<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


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