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


C# SessionFactory.BeginTransaction方法代码示例

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


在下文中一共展示了SessionFactory.BeginTransaction方法的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<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

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

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

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

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

示例7: Exam

        public ActionResult Exam(FormCollection collection, long[] ids)
        {
            if (ids.Length == 0)
            {
                FlashWarn("考试不存在!请联系管理员!");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                session.BeginTransaction();

                var models = session.Find<ExamAnswer>(m => m.TrainManagementItemId == ids[0]);
                if (models == null || !models.Any())
                {
                    FlashWarn("用户答题记录不在在!请联系管理员!");
                    return Close();
                }
                var trainManagementItem = session.Load<TrainManagementItem>(ids[0]);
                if (trainManagementItem == null)
                {
                    FlashWarn("用户答题记录不在在!请联系管理员!");
                    return Close();
                }
                trainManagementItem.ExamScore = 0;
                foreach (var question in models)
                {
                    var score = GetDbQueryPara(question.Id + "");
                    try
                    {
                        question.Score = score==null||score.Equals("")?0:Decimal.Parse(score);
                        trainManagementItem.ExamScore += question.Score;
                    }
                    catch (Exception)
                    {

                        FlashError("评分输入错误!");
                        return Close();
                    }
                }

                trainManagementItem.ExamStatus = ExamStatusConst.已评阅;
                trainManagementItem.UpdatedAt = DateTime.Now;
                trainManagementItem.UpdatedBy = "SYSTEM";
                if (session.Update(trainManagementItem) && session.Update(models))
                {
                    session.Commit();
                    Response.Write("<script>window.close()</script>");
                    return Close();
                }
                session.Rollback();
                FlashError("提交试卷不成功,请联系管理员!");
                return View(models);
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:54,代码来源:ExamMarkAnswerController.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 dept = new Criteria<Department>(session)
                  .AndIn<User>(m => m.Id, n => n.DepartmentId, m => m.Code.Equals(CurrentAccountNo)).Load();
                var models = session.Find<TrainNeed>(m => !m.IsCollected && m.Status.Equals(TrainNeedStatus.已提交部门负责人) && m.DeptId == dept.Id && m.Type.Equals(TrainNeedType.员工));
                if (models == null || !models.Any())
                {
                    FlashWarn("没有未汇总的需求!");
                    return Close();
                }
                foreach (var trainNeed in models)
                {
                    trainNeed.IsCollected = true;
                }
                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.部门;
                ViewData.Model = model;
                ViewData["StaffNeeds"] = models;
                var exist = session.Load<TrainNeed>(m => m.Type.Equals(TrainNeedType.部门) && m.DeptId.Equals(model.DeptId) && 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,代码行数:49,代码来源:TrainNeedDepartmentController.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: 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

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

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

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

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

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


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