本文整理汇总了C#中SessionFactory.Load方法的典型用法代码示例。如果您正苦于以下问题:C# SessionFactory.Load方法的具体用法?C# SessionFactory.Load怎么用?C# SessionFactory.Load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SessionFactory
的用法示例。
在下文中一共展示了SessionFactory.Load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
}
示例2: 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();
}
}
示例3: 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();
}
}
示例4: 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);
}
}
示例5: 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);
}
}
示例6: 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();
}
}
示例7: 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);
}
}
示例8: 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();
}
}
示例9: 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;
}
}
示例10: 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();
}
}
示例11: 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();
}
}
示例12: 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);
}
}
示例13: ApproveLeader
public ActionResult ApproveLeader(long[] ids, long id = 0)
{
using (var session = new SessionFactory().OpenSession())
{
var model = session.Load<TrainRecordFile>(m => m.Id.In(ids));
if (model == null)
{
FlashInfo("你没有选择任何可以修改的记录。");
return Close();
}
return View(model);
}
}
示例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();
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();
}
}
示例15: 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();
}
}