本文整理汇总了C#中SessionFactory.Commit方法的典型用法代码示例。如果您正苦于以下问题:C# SessionFactory.Commit方法的具体用法?C# SessionFactory.Commit怎么用?C# SessionFactory.Commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SessionFactory
的用法示例。
在下文中一共展示了SessionFactory.Commit方法的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();
}
}
示例2: 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();
}
}
示例3: 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();
}
}
示例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();
}
}
示例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();
}
}
示例6: 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();
}
}
示例7: 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();
}
}
示例8: 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();
}
}
示例9: 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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例14: 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<User>(m => m.Id.In(ids) && !m.IsActive);
var rootModel = models.FirstOrDefault(m => m.Code.Equals("root"));
if (rootModel != null)
{
FlashWarn("你不能删除ROOT账户。");
models.Remove(rootModel);
}
if (models.Count == 0)
{
FlashInfo("你没有选择任何可以删除的用户。为了系统安全考虑,已禁用的账户才能被删除。");
return Close();
}
var users = string.Join(", ", models.Select(m => m.Name));
foreach (var model in models)
{
if (!session.Delete(model) || !session.Delete<Account>(m => m.Name.Equals(model.Code)))
{
session.Rollback();
FlashError("删除用户{0}失败!", users);
return Delete(ids);
}
}
session.Commit();
UserActivity.UserNameIdMapHolder.Reset();
FlashSuccess("删除用户{0}成功!", users);
return Close();
}
}
示例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();
}
}