/// <summary> /// 创建一个角色 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="db">数据库上下文</param> /// <param name="entity">一个角色</param> /// <returns></returns> public bool Create(ref ValidationErrors validationErrors, SysEntities db, SysRole entity) { int count = 1; foreach (var item in entity.SysPersonId.GetIdSort()) { SysPerson sys = new SysPerson { Id = item }; db.SysPerson.Attach(sys); entity.SysPerson.Add(sys); count++; } foreach (var item in entity.SysMenuId.GetIdSort()) { SysMenu sys = new SysMenu { Id = item }; db.SysMenu.Attach(sys); entity.SysMenu.Add(sys); count++; } repository.Create(db, entity); if (count == repository.Save(db)) { return(true); } else { validationErrors.Add("创建出错了"); } return(false); }
/// <summary> /// 编辑一个模块 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="db">数据上下文</param> /// <param name="entity">一个模块</param> /// <returns>是否编辑成功</returns> public bool Edit(ref ValidationErrors validationErrors, SysEntities db, SysMenu entity) { /* * 不操作 原有 现有 * 增加 原没 现有 * 删除 原有 现没 */ if (entity == null) { return(false); } int count = 1; SysMenu editEntity = repository.Edit(db, entity); List <string> addSysRoleId = new List <string>(); List <string> deleteSysRoleId = new List <string>(); GetDiffrent(entity.SysRoleId.GetIdSort(), entity.SysRoleIdOld.GetIdSort(), ref addSysRoleId, ref deleteSysRoleId); if (addSysRoleId != null && addSysRoleId.Count() > 0) { foreach (var item in addSysRoleId) { SysRole sys = new SysRole { Id = item }; db.SysRole.Attach(sys); editEntity.SysRole.Add(sys); count++; } } if (deleteSysRoleId != null && deleteSysRoleId.Count() > 0) { List <SysRole> listEntity = new List <SysRole>(); foreach (var item in deleteSysRoleId) { SysRole sys = new SysRole { Id = item }; listEntity.Add(sys); db.SysRole.Attach(sys); } foreach (SysRole item in listEntity) { editEntity.SysRole.Remove(item);//查询数据库 count++; } } if (count == repository.Save(db)) { return(true); } else { validationErrors.Add("编辑模块出错了"); } return(false); }
/// <summary> /// 修改状态 /// </summary> /// <param name="menuID"></param> /// <param name="status"></param> /// <returns></returns> public int ChangeStatus(int?menuID, int?status) { SysMenu entity = handle.Detail(ConvertHelper.ToInt32(menuID)); using (TransactionScope transaction = new TransactionScope()) { entity.Status = status; if (handle.Edit(entity) != OperationWidget.Success) { return(OperationWidget.Failed); } transaction.Complete(); return(OperationWidget.Success); } }
public int Add(SysMenu entity) { if (VerificationWidget.IsExit(nameof(SysMenu), nameof(SysMenu.MenuCode), entity.MenuCode, nameof(SysMenu.MenuID), entity.MenuID) || VerificationWidget.IsExit(nameof(SysMenu), nameof(SysMenu.MenuName), entity.MenuName, nameof(SysMenu.MenuID), entity.MenuID)) { return(OperationWidget.IsRepeated); } using (TransactionScope transaction = new TransactionScope()) { if (handle.Add(entity) != OperationWidget.Success) { return(OperationWidget.Failed); } transaction.Complete(); return(OperationWidget.Success); } }
/// <summary> /// 编辑一个模块 /// </summary> /// <param name="validationErrors">返回的错误信息</param> /// <param name="entity">一个模块</param> /// <returns>是否编辑成功</returns> public bool Edit(ref ValidationErrors validationErrors, SysMenu entity) { try { using (TransactionScope transactionScope = new TransactionScope()) { if (Edit(ref validationErrors, db, entity)) { transactionScope.Complete(); return(true); } else { Transaction.Current.Rollback(); } } } catch (Exception ex) { validationErrors.Add(ex.Message); ExceptionsHander.WriteExceptions(ex); } return(false); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(SysMenu model) { return(dal.Edit(model)); }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(SysMenu model) { return(dal.Add(model)); }