/// <summary> /// 保存 /// </summary> /// <param name="model"></param> /// <returns>true or false</returns> public bool SaveList(List <D_Board_User_Role_Model> models) { NHibernate.ITransaction tran = NhSession.BeginTransaction(); try { foreach (var item in models) { NhSession.SaveOrUpdate(item); } tran.Commit(); return(true); } catch (Exception ex) { throw ex; } finally { if (!tran.WasCommitted && !tran.WasRolledBack) { tran.Rollback(); } } }
public bool SaveWorkFlowLog(D_Report_Model model, D_WorkFlowLog_Model logModel) { NHibernate.ITransaction tran = NhSession.BeginTransaction(); try { logModel.ReportGuid = model; NhSession.SaveOrUpdate(model.ReportD2); NhSession.SaveOrUpdate(model); if (model.ReportD8DataModels.Count > 0) { foreach (var item in model.ReportD8DataModels) { NhSession.SaveOrUpdate(item); } } if (model.WorkFlow_Models.Count > 0) { foreach (var item in model.WorkFlow_Models) { NhSession.SaveOrUpdate(item); } } if (model.WorkFlowLog_Models.Count > 0) { foreach (var item in model.WorkFlowLog_Models) { NhSession.SaveOrUpdate(item); } } NhSession.SaveOrUpdate(model); tran.Commit(); return(true); } catch (Exception ex) { throw ex; } finally { if (!tran.WasCommitted && !tran.WasRolledBack) { tran.Rollback(); } } }
/// <summary> /// 删除数据字典 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool Delete(D_Dictionary_Model model) { NHibernate.ITransaction tran = NhSession.BeginTransaction(); try { NhSession.Delete(model); tran.Commit(); return(true); } catch (Exception ex) { throw ex; } finally { if (!tran.WasCommitted && !tran.WasRolledBack) { tran.Rollback(); } } }
public ActionResult Role_Permission_Edit() { bool success = false; string roleGuid = Request.Form["RoleGuid"]; string permissions = Request.Form[2].ToString(); string[] permission = permissions.Split(','); using (NHibernate.ITransaction tran = NhSession.BeginTransaction()) { try { Guid RoleGuid = new Guid(roleGuid); Model.D_Role_Model role = NhSession.Get <Model.D_Role_Model>(RoleGuid); ICriteria ic = NhSession.CreateCriteria(typeof(Model.D_Role_Permissions_Model)); ic.Add(Restrictions.Eq("RoleGuid", role)); IList <Model.D_Role_Permissions_Model> rolePermissionList = ic.List <Model.D_Role_Permissions_Model>(); foreach (var item in rolePermissionList) { item.DataStatus = true; item.ModifyDateTime = DateTime.Now; item.ModifyUserGuid = UserView.UserGuid; item.ModifyUserName = UserView.UserName; NhSession.Update(item); } foreach (var item in permission) { Model.D_Role_Permissions_Model rolePermission = rolePermissionList.SingleOrDefault(m => m.Permissions == item); if (rolePermission == null) { rolePermission = new Model.D_Role_Permissions_Model(); rolePermission.CreateDateTime = DateTime.Now; rolePermission.CreateUserGuid = UserView.UserGuid; rolePermission.CreateUserName = UserView.UserName; rolePermission.RoleGuid = role; rolePermission.Permissions = item; } rolePermission.DataStatus = false; rolePermission.ModifyDateTime = DateTime.Now; rolePermission.ModifyUserGuid = UserView.UserGuid; rolePermission.ModifyUserName = UserView.UserName; NhSession.SaveOrUpdate(rolePermission); } tran.Commit(); return(Json(new { success = success, message = "成功" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { success = success, message = ex.Message })); } finally { if (!tran.WasCommitted && !tran.WasRolledBack) { tran.Rollback(); } } } }