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


C# SessionFactory类代码示例

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


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


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