本文整理汇总了C#中SessionFactory.Create方法的典型用法代码示例。如果您正苦于以下问题:C# SessionFactory.Create方法的具体用法?C# SessionFactory.Create怎么用?C# SessionFactory.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SessionFactory
的用法示例。
在下文中一共展示了SessionFactory.Create方法的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: 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();
}
}
示例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();
}
}
示例4: 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);
}
}
示例5: 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();
}
}
示例6: WriteLog
public static void WriteLog(ControllerContext controllerContext, ViewDataDictionary viewData)
{
var cc = controllerContext.Controller.ControllerContext;
var category = GetCategory(controllerContext);
var title = GetTitle(controllerContext);
var log = new ActionLog
{
Controller = cc.RouteData.GetRequiredString("controller"),
Action = cc.RouteData.GetRequiredString("action"),
Url = controllerContext.HttpContext.Request.Path,
CreatedAt = DateTime.Now,
CreatedBy = "SYSTEM",
Address = controllerContext.HttpContext.Request.UserHostAddress,
Actor = TryGetUserName(controllerContext),
Method = controllerContext.HttpContext.Request.HttpMethod,
Category = GetCategory(controllerContext),
Title = title.Equals(category) ? "查询" : title,
Result = TryGetResult(controllerContext),
ModelId = cc.RouteData.Values.ContainsKey("id") ? cc.RouteData.GetRequiredString("id") : null,
Description = viewData.ContainsKey(Const.ToLogMessage) ? viewData[Const.ToLogMessage].ToString() : null
};
if (log.Description == null && viewData.ContainsKey(Const.ToLogModel))
{
// 取得描述
var model = viewData.ContainsKey(Const.ToLogModel) ? viewData[Const.ToLogModel] : viewData.Model;
if (model != null)
{
if (!model.GetType().IsGenericType)
{
log.Description = model.Print();
}
else
{
var objs = (IEnumerable<object>)model;
log.Description = string.Join(";" + Environment.NewLine, objs.Select(m => m.Print()));
}
}
}
using (var ds = new SessionFactory().OpenSession())
{
if (!ds.Create(log))
{
Log.Error("记录日志失败:{0}", log.ToString());
}
}
}
示例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 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();
}
}
示例8: 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();
}
}
示例9: 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();
}
}
示例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();
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();
}
}
示例11: 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();
}
}
示例12: CreateLog
//#region 通用控制器模块
//public ActionResult CommonCreate<TModel>(FormCollection collection,
// Func<Session, bool> onTouch = null,
// Func<TModel, Session, bool> beforePersistance = null,
// Func<TModel, Session, bool> afterPersistance = null
// ) where TModel : class, new()
//{
// using (var session = new SessionFactory().OpenSession())
// {
// try
// {
// session.BeginTransaction();
// if (onTouch != null && !onTouch(session))
// {
// return Close();
// }
// var model = new TModel();
// TryUpdateModel(model, collection);
// if (!ModelState.IsValid)
// {
// // ReSharper disable Mvc.ViewNotResolved
// return View(model);
// // ReSharper restore Mvc.ViewNotResolved
// }
// if (beforePersistance != null && !beforePersistance(model, session))
// {
// return Close();
// }
// if (typeof(TModel).GetInterface("IDboFollow") == typeof(IDboFollow))
// {
// model.SetPropertyValue("CreatedAt", DateTime.Now);
// model.SetPropertyValue("CreatedBy", CurrentAccountNo);
// }
// if (session.Create(model))
// {
// if (afterPersistance == null || afterPersistance(model, session))
// {
// session.Commit();
// FlashSuccess("{0}创建成功", SchemaHelper.GetObjectName<TModel>());
// return Close();
// }
// }
// session.Rollback();
// FlashFailure("创建{0}失败!", SchemaHelper.GetObjectName<TModel>());
// return View(model);
// }
// catch (Exception ex)
// {
// session.Rollback();
// FlashError("发生错误:{0}", ex.Message);
// return View();
// }
// }
//}
//#endregion
protected void CreateLog(string result = null, string description = null)
{
using (var session = new SessionFactory().OpenSession())
{
var log = new ActionLog
{
Controller = ControllerName,
Action = ActionName,
ModelId = ModelId,
UserId = CurrentAccountId,
Url = Url,
CreatedAt = DateTime.Now,
CreatedBy = "SYSTEM",
Address = Request.UserHostAddress,
Actor = CurrentAccountNo,
Category = GetCategory(),
Title = GetTitle(),
Result = result,
Description = description
};
if (!session.Create(log))
{
Log.Error("记录日志失败:{0}", log.ToString());
}
}
}
示例13: Create
public ActionResult Create(FormCollection collection)
{
var model = new Record();
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;
model.Time = DateTime.Now;
model.Undertaker = 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.State = "";
model.ApproveState = "";
ViewData.Model = model;
if (session.Create(model))
{
session.Commit();
FlashSuccess("创建记录成功!");
return Close();
}
session.Rollback();
FlashFailure("创建记录失败!");
return Close();
}
}
示例14: Exam
public ActionResult Exam(FormCollection collection, long[] ids)
{
if (ids.Length == 0)
{
FlashWarn("考试不存在!请联系管理员!");
return Close();
}
using (var session = new SessionFactory().OpenSession())
{
session.BeginTransaction();
var trainManagementItem = session.Load<TrainManagementItem>(ids[0]);
if (trainManagementItem == null)
{
session.Rollback();
FlashWarn("培训明细不存在!请联系管理员!");
return Close();
}
var exam = session.Load<Exam>(m => m.TrainManId == trainManagementItem.TrainManId);
if (exam == null)
{
session.Rollback();
FlashWarn("考试不存在!请联系管理员!");
return Close();
}
ViewData["ExamContent"] = exam.HtmlContent;
var models = session.Find<Question>(m => m.ExamId == exam.Id);
if (models == null || !models.Any())
{
session.Rollback();
FlashWarn("考试题目未设置!");
return Close();
}
var answerList = new List<ExamAnswer>();
foreach (var question in models)
{
var answerStr = GetDbQueryPara(question.Id + "");
var answer = new ExamAnswer
{
CreatedAt = DateTime.Now,
CreatedBy = "SYSTEM",
Answer = answerStr,
QuestionId = question.Id,
StaffCode = CurrentAccountNo,
StaffName = CurrentAccountNo.GetName(),
TrainManagementItemId = trainManagementItem.Id
};
if(question.Type.Contains("选"))
{
answer.Score = answer.Answer.Replace(",", "").ToUpper().Equals(question.RightAnswer.ToUpper()) ? question.Value : 0;
}
answerList.Add(answer);
}
trainManagementItem.ExamStatus = ExamStatusConst.已考试;
trainManagementItem.UpdatedAt = DateTime.Now;
trainManagementItem.UpdatedBy = "SYSTEM";
if (session.Update(trainManagementItem) && session.Create(answerList))
{
session.Commit();
Response.Write("<script>window.close()</script>");
return Close();
}
session.Rollback();
FlashError("提交试卷不成功,请联系管理员!");
return View(models);
}
}
示例15: AddRole
//public bool AddOrganization(Organization organization)
//{
// if (organization == null || organization.Id <= 0) return false;
// if (Id <= 0) return false;
// var q = new Criteria<AccountOrganizationRef>().Where(m => m.AccountId.Equals(Id) && m.OrganizationId.Equals(organization.Id));
// if (q.Count() > 0) return true;
// var r = new AccountOrganizationRef { AccountId = Id, OrganizationId = organization.Id };
// var db = new SessionFactory().OpenSession();
// return db.Create(r);
//}
public bool AddRole(Role role)
{
if (role == null || role.Id <= 0) return false;
if (Id <= 0) return false;
Criteria<AccountRoleRef> q =
new Criteria<AccountRoleRef>().Where(m => m.AccountId.Equals(Id) && m.RoleId.Equals(role.Id));
if (q.Count() > 0) return true;
Session db = new SessionFactory().OpenSession();
var r = new AccountRoleRef { AccountId = Id, RoleId = role.Id };
return db.Create(r);
}