private OPResult Add(SysRoleBO role) { role.CreatorID = VMGlobal.CurrentUser.ID; role.OrganizationID = VMGlobal.CurrentUser.OrganizationID; using (TransactionScope scope = new TransactionScope()) { try { int id = LinqOP.Add <SysRole, int>(role, r => r.ID); role.ID = id; List <SysRoleModule> rms = new List <SysRoleModule>(); foreach (var m in role.Modules) { SysRoleModule rm = new SysRoleModule { RoleId = id, ModuleId = m.ID }; rms.Add(rm); } LinqOP.Add <SysRoleModule>(rms); if (_rolesOfCurrentOrgnization != null)//新增成功后同步更新_rolesOfCurrentOrgnization { _rolesOfCurrentOrgnization.Add(role); } scope.Complete(); return(new OPResult { IsSucceed = true, Message = "保存成功." }); } catch (Exception e) { role.ID = default(int); return(new OPResult { IsSucceed = false, Message = "保存失败,失败原因:\n" + e.Message }); } } }
public override OPResult AddOrUpdate(SysRole entity) { SysRoleBO role = (SysRoleBO)entity; return(role.ID == default(int) ? this.Add(role) : this.Update(role)); }