• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# SessionFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

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


示例2: Create

 public ActionResult Create(FormCollection collection)
 {
     var model = new Role();
     TryUpdateModel(model, collection.ToValueProvider());
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     using (var session = new SessionFactory().OpenSession())
     {
         if (session.Load<Role>(m => m.Name.Equals(model.Name)) != null)
         {
             FlashFailure("角色名称[{0}]已经存在,创建失败!", model.Name);
             return View(model);
         }
         model.CreatedAt = DateTime.Now;
         model.CreatedBy = CurrentAccountNo;
         ViewData.Model = model;
         if (session.Create(model))
         {
             FlashSuccess("角色[{0}]创建成功", model.Name);
             return Close();
         }
         FlashFailure("创建角色[{0}]失败!", model.Name);
         return View(model);
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:27,代码来源:RoleController.cs


示例3: Create

        public ActionResult Create(FormCollection collection)
        {
            var model = new SchoolDepartment();
            TryUpdateModel(model, collection.ToValueProvider());
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            using (var session = new SessionFactory().OpenSession())
            {
                //model.ParentId
                //model.LeaderId
                model.LeaderName = model.LeaderId == 0 ? "" : session.Load<User>(model.LeaderId).Realname;

                if (session.Load<SchoolDepartment>(m => m.Name.Equals(model.Name)) != null)
                {
                    FlashFailure("部门[{0}]已经存在", model.Name);
                    return View(model);
                }
                model.CreatedAt = DateTime.Now;
                model.CreatedBy = CurrentAccountNo;
                ViewData.Model = model;
                if (session.Create(model))
                {
                    FlashSuccess("部门[{0}]创建成功", model.Name);
                    return Close();
                }
                FlashFailure("创建部门[{0}]失败!", model.Name);
                return View();
            }
        }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:31,代码来源:SchoolDepartmentController.cs


示例4: Approve

 public ActionResult Approve(FormCollection collection, long[] ids)
 {
     if (ids.Length == 0)
     {
         FlashWarn("请选择要修改的记录。");
         return Close();
     }
     using (var session = new SessionFactory().OpenSession())
     {
         var model = session.Load<TrainManagement>(m => m.Id.In(ids));
         if (model == null)
         {
             FlashInfo("你没有选择任何可以审核的记录。");
             return Close();
         }
         if (!CanApprove(model))
         {
             FlashWarn("无法审核,请检查所选记录状态!");
             return Close();
         }
         model.Status = TrainManStateConst.法规部门负责人已审核;
         model.UpdatedAt = DateTime.Now;
         model.UpdatedBy = CurrentAccountNo;
         if (session.Update(model))
             FlashSuccess("记录审核成功");
         else
             FlashError("记录审核失败,请联系管理员!");
         return Close();
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:30,代码来源:TrainManagementController.cs


示例5: 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<School>(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;
         if (session.Update(model))
         {
             FlashSuccess("学校更改成功");
             return Close();
         }
         return View();
     }
 }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:30,代码来源:SchoolController.cs


示例6: Install

        public ActionResult Install(string check)
        {
            SessionFactory CreateSession = new SessionFactory();
            CreateSession.CreateSessionFactory<PostMapping>();

            return RedirectToAction("Create");
        }
开发者ID:nicholaspei,项目名称:DevText,代码行数:7,代码来源:postController.cs


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


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


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


示例10: GetFileContent

 public ActionResult GetFileContent(long id = 0)
 {
     if (id == 0)
     {
         return null;
     }
     using (var session = new SessionFactory().OpenSession())
     {
         var model = session.Load<TrainStudyFiles>(id);
         if (model == null)
         {
             return null;
         }
         if (model.Suffix.Contains("doc"))
         {
             var src = model.HtmlFilePath;
             var path = Server.MapPath(src);
             if (!System.IO.File.Exists(path))
             {
                 FlashWarn("文件不存在!");
                 return Close();
             }
             var content = string.Format(@"<iframe src=""{0}"" width=""100%"" height=""600px""></iframe>", src);
             Response.Write(content);
         }
         else
         {
             Response.Write(model.FlvHtml);
         }
         return null;
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:32,代码来源:TrainStudyController.cs


示例11: Submit

 public ActionResult Submit(long[] ids)
 {
     if (ids.Length == 0)
     {
         FlashWarn("请选择要操作的记录。");
         return Close();
     }
     using (var session = new SessionFactory().OpenSession())
     {
         var model = session.Load<TrainNeed>(m => m.Id.In(ids));
         if (model == null)
         {
             FlashWarn("没有可以操作的记录。");
             return Close();
         }
         if (!model.Type.Equals(TrainNeedType.公司))
         {
             FlashInfo("只能提交类型为\"公司\"的记录!");
             return Close();
         }
         if (!CanSubmit(model))
         {
             FlashWarn("该记录已经提交。");
             return Close();
         }
         return View(model);
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:28,代码来源:TrainNeedInchargeLeaderController.cs


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


示例13: Approve

        public ActionResult Approve(FormCollection collection, long[] ids, long id = 0)
        {
            if (ids.Length == 0)
            {
                FlashWarn("请选择要批阅的记录。");
                return Close();
            }
            using (var session = new SessionFactory().OpenSession())
            {
                var model = session.Load<TrainRecordFile>(m => m.Id.In(ids));
                if (model == null)
                {
                    FlashInfo("你没有选择任何可以批阅的记录。");
                    return Close();
                }
                TryUpdateModel(model, collection.ToValueProvider());
                model.UpdatedAt = DateTime.Now;
                model.UpdatedBy = CurrentAccountNo;
                if (session.Update(model))
                {
                    FlashSuccess("批阅记录成功");
                    return Close();
                }
                FlashFailure("批阅记录失败,请联系管理员!");
                return View();

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


示例14: Index

        //[Priviledge(Name = "首页", IsMenu = true, IsEntry = true, Position = 1)]
        public ActionResult Index()
        {
            using (var session = new SessionFactory().OpenSession())
            {
                const string accountNavigationSql =
                    "SELECT * FROM `navigations` WHERE `type` < 4 AND ((`auth_code` = 0) OR (`id` IN ( SELECT `navigation_id` FROM `navigation_priviledges` WHERE (`flag` = 1 AND `owner_id` IN (SELECT `role_id` FROM `account_role_refs` WHERE `account_id` IN ( SELECT `id` FROM `accounts` WHERE `name` = '{0}'))) OR (`flag` = 2 AND `owner_id` IN ( SELECT `id` FROM `accounts` WHERE `name` = '{0}'))))) ORDER BY `order_id` asc";
                var accountNavs =
                    session.FindBySql<Navigation>(string.Format(accountNavigationSql, CurrentAccountNo));
                Session.Add(Const.AccountMenuItems, accountNavs);

                const string rolePinNavigationSql =
                    "SELECT n.* FROM `account_navigation_refs` r LEFT JOIN `navigations` n ON r.`navigation_id` = n.`id` WHERE r.`type` = 1 AND r.`owner_id` IN (SELECT `role_id` FROM `account_role_refs` WHERE `account_id` IN ( SELECT `id` FROM `accounts` WHERE `name` = '{0}')) ORDER BY r.`order_id` ASC";
                var pinRoleNavs =
                    session.FindBySql<Navigation>(string.Format(rolePinNavigationSql, CurrentAccountNo));
                Session.Add(Const.RolePinnedTask, pinRoleNavs);

                const string accountPinNavigationSql =
                    "SELECT n.* FROM `account_navigation_refs` r LEFT JOIN `navigations` n ON r.`navigation_id` = n.`id` WHERE r.`type` = 2 AND r.`owner_id` IN ( SELECT `id` FROM `accounts` WHERE `name` = '{0}') ORDER BY r.`order_id` ASC";
                var pinAccountNavs =
                    session.FindBySql<Navigation>(string.Format(accountPinNavigationSql, CurrentAccountNo));
                Session.Add(Const.AccountPinnedTask, pinAccountNavs);

                var model = session.Load<Account>(m => m.Name.Equals(CurrentAccountNo));

                return View(model);
            }
        }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:28,代码来源:PortalController.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<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


示例16: Edit

 public ActionResult Edit(long[] ids)
 {
     using (var session = new SessionFactory().OpenSession())
     {
         var model = session.Load<TrainManagementItem>(ids[0]);
         if (model.ExamStatus != null && !model.ExamStatus.Equals(ExamStatusConst.未考试))
         {
             FlashWarn("您已经完成该考试!");
             return Close();
         }
         var q = new Criteria<Exam>(session)
          .AndIn<TrainManagementItem>(m => m.TrainManId, n => n.TrainManId, n => n.Id == ids[0]);
         var exam = q.Load();
         if (exam == null)
         {
             FlashWarn("考试不存在!请联系管理员!");
             return Close();
         }
         var models = session.Find<Question>(m => m.ExamId == exam.Id);
         if (models == null || !models.Any())
         {
             FlashWarn("考试题目未设置!");
             return Close();
         }
         Response.Write(string.Format("<script>window.open('Exam?ids={0}','_blank')</script>", ids[0]));
         return Close();
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:28,代码来源:OnlineExamController.cs


示例17: Delete

 public ActionResult Delete(long[] ids, long id = 0)
 {
     if (ids.Length == 0)
     {
         FlashInfo("请选择要删除的记录。");
         return Close();
     }
     using (var session = new SessionFactory().OpenSession())
     {
         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();
         }
         return View(models);
     }
 }
开发者ID:dalinhuang,项目名称:info_platform_i,代码行数:34,代码来源:PunishmentDossierFilesController.cs


示例18: OrganizationList

 public static SelectList OrganizationList()
 {
     Session ds = new SessionFactory().OpenSession();
     IList<Organization> d = ds.Find<Organization>();
     var item = new Organization {Id = 0, Name = "无"};
     d.Add(item);
     return new SelectList(d, "Id", "Name");
 }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:8,代码来源:SelectListFactory.cs


示例19: AreaCodeHelper

 static AreaCodeHelper()
 {
     if (_areaCodes != null) return;
     using (var session = new SessionFactory().OpenSession())
     {
         _areaCodes = new Criteria<AreaCode>(session).Find();
     }
 }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:8,代码来源:AreaCodeHelper.cs


示例20: SupplierList

 public static SelectList SupplierList()
 {
     Session ds = new SessionFactory().OpenSession();
     IList<Supplier> d = ds.Find<Supplier>();
     var item = new Supplier {Id = 0, Name = "无"};
     d.Add(item);
     return new SelectList(d, "Id", "Name");
 }
开发者ID:dalinhuang,项目名称:info_platform,代码行数:8,代码来源:SelectListFactory.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# SessionID类代码示例发布时间:2022-05-24
下一篇:
C# SessionEventArgs类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap