public virtual bool Edit(SysRoleModel model) { try { tbl_SysRole entity = m_Rep.GetById(model.Id); if (entity == null) { return(false); } entity.Id = model.Id; entity.RoleId = model.RoleId; entity.RoleName = model.RoleName; entity.IsShow = model.IsShow; if (m_Rep.Edit(entity)) { return(true); } else { return(false); } } catch (Exception ex) { 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, SysRole entity) { /* * 不操作 原有 现有 * 增加 原没 现有 * 删除 原有 现没 */ if (entity == null) { return(false); } int count = 1; SysRole editEntity = repository.Edit(db, entity); List <string> addSysPersonId = new List <string>(); List <string> deleteSysPersonId = new List <string>(); DataOfDiffrent.GetDiffrent(entity.SysPersonId.GetIdSort(), entity.SysPersonIdOld.GetIdSort(), ref addSysPersonId, ref deleteSysPersonId); if (addSysPersonId != null && addSysPersonId.Count() > 0) { foreach (var item in addSysPersonId) { SysPerson sys = new SysPerson { Id = item }; db.SysPerson.Attach(sys); editEntity.SysPerson.Add(sys); count++; } } if (deleteSysPersonId != null && deleteSysPersonId.Count() > 0) { List <SysPerson> listEntity = new List <SysPerson>(); foreach (var item in deleteSysPersonId) { SysPerson sys = new SysPerson { Id = item }; listEntity.Add(sys); db.SysPerson.Attach(sys); } foreach (SysPerson item in listEntity) { editEntity.SysPerson.Remove(item);//查询数据库 count++; } } if (count == repository.Save(db)) { return(true); } else { validationErrors.Add("编辑角色出错了"); } return(false); }