public virtual bool Edit(ref ValidationErrors errors, SysRightModel model) { try { SysRight entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return(false); } entity.Id = model.Id; entity.ModuleId = model.ModuleId; entity.RoleId = model.RoleId; entity.Rightflag = model.Rightflag; if (m_Rep.Edit(entity)) { return(true); } else { errors.Add(Resource.NoDataChange); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
private void RemoveRoleRight(string roleId, string moduleId) { SysRight right = m_Rep.GetList(r => r.RoleId == roleId && r.ModuleId == moduleId).FirstOrDefault(); if (right != null) { m_Rep.RemoveById(right.Id); DBSession.SaveChanges(); SysModule curModule = DBSession.SysModule.GetById(moduleId); IQueryable <SysModule> modules = DBSession.SysModule.GetList(m => m.ParentId == curModule.ParentId); int count = 0; foreach (var item in modules) { if (count > 0) { break; } if (m_Rep.GetList(r => r.RoleId == roleId && r.ModuleId == item.Id).Count() > 0) { count++; } } if (count == 0) { RemoveRoleRight(roleId, curModule.ParentId); } } }
public virtual bool Create(ref ValidationErrors errors, SysRightModel model) { try { SysRight entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(false); } entity = new SysRight(); entity.Id = model.Id; entity.ModuleId = model.ModuleId; entity.RoleId = model.RoleId; entity.Rightflag = model.Rightflag; if (m_Rep.Create(entity)) { return(true); } else { errors.Add(Resource.InsertFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
/// <summary> /// 删除父级菜单权限关联 /// </summary> /// <param name="sysRight">权限</param> /// <param name="delMenu">菜单</param> private void DeleteRightParentMenu(SysRight sysRight, SysMenu delMenu) { //SysRightMenu sysRightMenu = new SysRightMenu(); //bool canDeleteParent = true; //List<SysMenu> subMenuList = delMenu.ParentMenu.SubMenus.ToList(); //foreach (SysMenu subMenu in subMenuList) //{ // if (subMenu.id == delMenu.id) // continue; // else // { // sysRightMenu = _sysRightMenuDal.Single(s => s.menu_id == subMenu.id && s.right_id == sysRight.id).Entity; // if (sysRightMenu != null) // { // //存在该菜单父菜单的其他子菜单关联 // canDeleteParent = false; // break; // } // } //} //if (canDeleteParent) //{ // //可以删除父菜单,则调用自身持续判断 // if (delMenu.ParentMenu.ParentMenu != null) // { // DeleteRightParentMenu(sysRight, delMenu.ParentMenu); // } // //退出后获得该关联项,加入删除 // sysRightMenu = _sysRightMenuDal.Single(s => s.menu_id == delMenu.ParentMenu.id && s.right_id == sysRight.id).Entity; // _unitOfWork.AddAction(sysRightMenu, DataActions.Delete); //} }
public void InitEditModel(SysRight sysRight) { this.Right = sysRight; this.RightCode = sysRight.RightCode; this.Name = sysRight.Name; this.Remark = sysRight.Remark; this.Stopped = sysRight.Stopped; if (sysRight.SysMenus != null) { ICollection<SysMenu> sysMenus = sysRight.SysMenus; this.SysMenus = new List<MenuEditModel>(); foreach (SysMenu sysMenu in sysMenus) { MenuEditModel menu = new MenuEditModel(); menu.InitEditModel(sysMenu); this.SysMenus.Add(menu); } } else { this.SysMenus = null; } }
/// <summary> /// 根据权限编号获取编辑对象 /// </summary> /// <param name="code">权限编号</param> public RightEditModel GetRightByCode(string code) { try { RightEditModel rightEditModel = new RightEditModel(); Repository<SysRight> sysRightDal = _unitOfWork.GetRepository<SysRight>(); SysRight sysRight = sysRightDal.GetObjectByKey(code).Entity; if (sysRight != null) { rightEditModel.InitEditModel(sysRight); } return rightEditModel; } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } }
public bool Edit(ref ValidationErrors errors, SysRightModel model) { try { SysRight entity = sysRightRep.GetById(model.Id); if (entity == null) { errors.Add(Suggestion.Disable); return(false); } entity.Id = model.Id; entity.ModuleId = model.ModuleId; entity.Rightflag = model.Rightflag; entity.RoleId = model.RoleId; if (sysRightRep.Edit(entity) == 1) { return(true); } else { errors.Add(Suggestion.EditFail); return(false); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(false); } }
public virtual void Modify(ref ValidationErrors errors, Apps.Models.Sys.SysRightModel model, params string[] updateProperties) { SysRight entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return; } if (updateProperties.Count() <= 0) { entity.Id = model.Id; entity.ModuleId = model.ModuleId; entity.RoleId = model.RoleId; entity.Rightflag = model.Rightflag; } else { Type type = typeof(Apps.Models.Sys.SysRightModel); Type typeE = typeof(Apps.Models.SysRight); foreach (var item in updateProperties) { System.Reflection.PropertyInfo pi = type.GetProperty(item); System.Reflection.PropertyInfo piE = typeE.GetProperty(item); piE.SetValue(entity, pi.GetValue(model), null); } } m_Rep.Modify(entity, updateProperties); }
public int Create(SysRight entity) { using (DBContainer db = new DBContainer()) { db.SysRight.Add(entity); return(db.SaveChanges()); } }
public static bool Insert(SysRight sysRight) { using (var context = db.Context()) { return(context.Insert <SysRight>("SysRight", sysRight) .Execute() > 0); } }
public ActionResult Create([Bind(Include = "ID,IsAvailable,Name,ParentID,ActionType,MenuUrl,Position,SortNo,DisplayName")] SysRight sysRight) { sysRight.AddBy = cuser.UserID; sysRight.AddByName = cuser.LoginName; sysRight.AddDate = DateTime.Now; sysRight.IsDel = false; sysRight.ParentID = string.IsNullOrEmpty(sysRight.ParentID) ? null : sysRight.ParentID; var parent = rightService.Find(sysRight.ParentID); if ((sysRight.ParentID == null) || parent != null) { sysRight.RightLevel = parent == null ? 1 : parent.RightLevel + 1; sysRight.RightIDPath = parent == null ? "/" + sysRight.ID + "/" : parent.RightIDPath + sysRight.ID + "/"; if (!string.IsNullOrEmpty(sysRight.ID)) { var exist = rightService.Exist(r => r.ID == sysRight.ID.Trim()); if (!exist) { rightService.Add(sysRight); if (rightService.SaveChanges(out msg) > 0) { CacheMaker.IISCache.Remove("all_sys_right"); return(Json(new AjaxResult() { success = true, msg = insertSuccess, url = Url.Action("treeindex", "sysright", "admin"), moremsg = msg })); } else { return(Json(new AjaxResult() { success = false, msg = insertFailure, moremsg = msg })); } } { return(Json(new AjaxResult() { success = false, msg = insertFailure + ",ID已被占用", moremsg = "ID已被占用" })); } } else { return(Json(new AjaxResult() { success = false, msg = insertFailure, moremsg = "ID不能为空" })); } } else { return(Json(new AjaxResult() { success = false, msg = insertFailure + ",上级权限ID只能为root或者已存在的权限的ID" })); } }
/// <summary> /// 判断编号是否存在 /// </summary> /// <param name="code">权限编号</param> private bool CheckCodeExists(string code) { Repository<SysRight> sysRightDal = _unitOfWork.GetRepository<SysRight>(); SysRight sysRight = sysRightDal.GetObjectByKey(code).Entity; if (sysRight != null) { return true; } return false; }
public int Edit(SysRight entity) { using (DBContainer db = new DBContainer()) { // db.SysRight.Attach(entity); // db.ObjectStateManager.ChangeObjectState(entity, EntityState.Modified); db.Set <SysRight>().Attach(entity); db.Entry(entity).State = System.Data.Entity.EntityState.Modified; return(db.SaveChanges()); } }
/// <summary> /// 更新权限信息 /// </summary> /// <param name="newRight">需要更新的权限信息</param> public RightEditModel Update(RightEditModel newRight) { try { Repository<SysRight> sysRightDal = _unitOfWork.GetRepository<SysRight>(); SysRight sysRight = sysRightDal.GetObjectByKey(newRight.RightCode).Entity; if (sysRight != null) { sysRight.Name = newRight.Name; sysRight.Remark = newRight.Remark; sysRight.Stopped = newRight.Stopped; sysRight.SysMenus.Clear(); if (newRight.SysMenus != null && newRight.SysMenus.Count > 0) { Repository<SysMenu> sysMenuDal = _unitOfWork.GetRepository<SysMenu>(); List<SysMenu> sysMenuList = sysMenuDal.GetAll().Entities.ToList(); foreach (MenuEditModel sysMenuTemp in newRight.SysMenus) { SysMenu sysMenu = sysMenuList.Single(sm => sm.MenuCode == sysMenuTemp.MenuCode); sysRight.SysMenus.Add(sysMenu); } } if (newRight.SysRoles != null && newRight.SysRoles.Count > 0) { sysRight.SysRoles.Clear(); Repository<SysRole> sysRoleDal = _unitOfWork.GetRepository<SysRole>(); List<SysRole> sysRoleList = sysRoleDal.GetAll().Entities.ToList(); foreach (RoleEditModel sysRoleTemp in newRight.SysRoles) { SysRole sysRole = sysRoleList.Single(sr => sr.RoleCode == sysRoleTemp.RoleCode); sysRight.SysRoles.Add(sysRole); } } } _unitOfWork.AddAction(sysRight, DataActions.Update); _unitOfWork.Save(); return newRight; } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } }
public static bool Update(SysRight sysRight) { using (var context = db.Context()) { return(context.Update <SysRight>("SysRight", sysRight) .AutoMap(x => x.Id) .Where("Id", sysRight.Id) .Execute() > 0); } }
public int Delete(string id) { using (DBContainer db = new DBContainer()) { SysRight entity = db.SysRight.SingleOrDefault(a => a.Id == id); if (entity != null) { db.SysRight.Remove(entity); } return(db.SaveChanges()); } }
public bool IsExist(string id) { using (DBContainer db = new DBContainer()) { SysRight entity = GetById(id); if (entity != null) { return(true); } return(false); } }
//[SupportFilter(ActionName = "Save")] public Boolean UpdateRight(SysRight model) { List <SysRight> right = sysRightBLL._SysRightRepository.FindList(a => a.RoleId == model.RoleId && a.ModuleId == model.ModuleId && a.MopId == model.MopId).ToList(); if (right.Count == 0 && model.IsValid == "true") { sysRightBLL._SysRightRepository.Create(model); } else if (right.Count != 0) { sysRightBLL._SysRightRepository.Delete(right); } return(true); }
/// <summary> /// 根据实体对象转换成显示对象 /// </summary> /// <param name="sysRight">需要转换的权限实体对象</param> private RightDisplayModel BuildModel(SysRight sysRight) { if (sysRight == null) { return null; } RightDisplayModel rightDisplayModel = new RightDisplayModel(); rightDisplayModel.Code = sysRight.RightCode; rightDisplayModel.Name = sysRight.Name; rightDisplayModel.Remark = sysRight.Remark; rightDisplayModel.Stopped = sysRight.Stopped.Value; return rightDisplayModel; }
public SysRight UpdateSysRight(SysRight updSysRight) { SysRight sysRight = null; try { _sysRightDal.Update(updSysRight); sysRight = updSysRight; } catch (RepositoryException ex) { throw new AisinoMesServiceException("修改权限信息失败!", ex); } return(sysRight); }
public SysRight AddSysRight(SysRight newSysRight) { SysRight sysRight = null; try { _sysRightDal.Add(newSysRight); sysRight = newSysRight; } catch (RepositoryException ex) { throw new AisinoMesServiceException("添加权限信息失败!", ex); } return(sysRight); }
public SysRight DeleteSysRight(SysRight delSysRight) { SysRight sysRight = null; try { delSysRight.right_deleted = true; _unitOfWork.AddAction(delSysRight, DataActions.Update); _unitOfWork.Save(); } catch (RepositoryException ex) { throw new AisinoMesServiceException("删除权限信息失败!", ex); } return(sysRight); }
public RightEditModel SetRightMenus(RightEditModel rightEditModel, List<string> menuCodes) { try { Repository<SysRight> sysRightDal = _unitOfWork.GetRepository<SysRight>(); SysRight sysRight = sysRightDal.GetObjectByKey(rightEditModel.RightCode).Entity; if (sysRight != null) { sysRight.Name = rightEditModel.Name; sysRight.Remark = rightEditModel.Remark; sysRight.Stopped = rightEditModel.Stopped; } //修改菜单 sysRight.SysMenus.Clear(); if (menuCodes != null && menuCodes.Count > 0) { List<SysMenu> sysMenuListTemp = new List<SysMenu>(); Repository<SysMenu> sysMenuDal = _unitOfWork.GetRepository<SysMenu>(); foreach (string menuCode in menuCodes) { SysMenu sysMenu = sysMenuDal.GetObjectByKey(menuCode).Entity; sysMenuListTemp.Add(sysMenu); } sysRight.SysMenus = sysMenuListTemp; } _unitOfWork.AddAction(sysRight, DataActions.Update); _unitOfWork.Save(); return rightEditModel; } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } }
public ActionResult Edit([Bind(Include = "ID,IsAvailable,Name,ParentID,AddBy,AddDate,ActionType,MenuUrl,Position,SortNo,DisplayName")] SysRight sysRight) { sysRight.UpdateBy = cuser.UserID; sysRight.UpdateByName = cuser.LoginName; sysRight.UpdateDate = DateTime.Now; sysRight.ParentID = string.IsNullOrEmpty(sysRight.ParentID) ? null : sysRight.ParentID; if (sysRight.ParentID != sysRight.ID) { var parent = rightService.Find(sysRight.ParentID); if (sysRight.ParentID == null || parent != null) { sysRight.RightLevel = parent == null ? 0 : parent.RightLevel + 1; sysRight.RightIDPath = parent == null ? "/" + sysRight.ID + "/" : parent.RightIDPath + sysRight.ID + "/"; rightService.Update(sysRight); if (rightService.SaveChanges(out msg) > 0) { CacheMaker.IISCache.Remove("all_sys_right"); return(Json(new AjaxResult() { success = true, msg = updateSuccess, url = Url.Action("treeindex", "sysright", "admin"), moremsg = msg })); } else { return(Json(new AjaxResult() { success = false, msg = updateFailure, moremsg = msg })); } } else { return(Json(new AjaxResult() { success = false, msg = updateFailure + ",上级权限ID只能为root或者已存在的权限的ID" })); } } else { return(Json(new AjaxResult() { success = false, msg = updateFailure + ",权限ID不能与上级权限的ID相同" })); } }
public virtual void Create(ref ValidationErrors errors, Apps.Models.Sys.SysRightModel model) { SysRight entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return; } entity = new SysRight(); entity.Id = model.Id; entity.ModuleId = model.ModuleId; entity.RoleId = model.RoleId; entity.Rightflag = model.Rightflag; m_Rep.Create(entity); }
public SysRightModel GetById(string id) { if (IsExist(id)) { SysRight entity = sysRightRep.GetById(id); SysRightModel model = new SysRightModel(); model.Id = entity.Id; model.ModuleId = entity.ModuleId; model.Rightflag = entity.Rightflag; model.RoleId = entity.RoleId; return(model); } else { return(null); } }
public virtual SysRightModel GetById(object id) { if (IsExists(id)) { SysRight entity = m_Rep.GetById(id); SysRightModel model = new SysRightModel(); model.Id = entity.Id; model.ModuleId = entity.ModuleId; model.RoleId = entity.RoleId; model.Rightflag = entity.Rightflag; return(model); } else { return(null); } }
public virtual async Task <SysRightModel> GetByIdAsync(object id) { if (IsExists(id)) { SysRight entity = await m_Rep.GetByIdAsync(id); SysRightModel model = new SysRightModel(); model.Id = entity.Id; model.ModuleId = entity.ModuleId; model.RoleId = entity.RoleId; model.Rightflag = entity.Rightflag; return(model); } else { return(null); } }
public virtual Apps.Models.Sys.SysRightModel GetById(string id) { SysRight entity = m_Rep.GetById(id); if (entity != null) { //SysRight entity = m_Rep.GetById(id); Apps.Models.Sys.SysRightModel model = new Apps.Models.Sys.SysRightModel(); model.Id = entity.Id; model.ModuleId = entity.ModuleId; model.RoleId = entity.RoleId; model.Rightflag = entity.Rightflag; return(model); } else { return(null); } }
/// <summary> /// 添加权限 /// </summary> /// <param name="newRight">需要添加的权限信息</param> public RightEditModel Add(RightEditModel newRight) { try { if (CheckCodeExists(newRight.RightCode)) { throw new FaultException<LCFault>(new LCFault("权限添加失败"), "该权限编号已存在,不能重复添加"); } if (CheckNameExists(newRight.Name)) { throw new FaultException<LCFault>(new LCFault("权限添加失败"), "该权限名称已存在,不能重复添加"); } SysRight sysRight = new SysRight(); sysRight.Name = newRight.Name; sysRight.Remark = newRight.Remark; sysRight.RightCode = newRight.RightCode; sysRight.Stopped = newRight.Stopped; _unitOfWork.AddAction(sysRight, DataActions.Add); _unitOfWork.Save(); return newRight; } catch (RepositoryException rex) { string msg = rex.Message; string reason = rex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } catch (Exception ex) { string msg = ex.Message; string reason = ex.StackTrace; throw new FaultException<LCFault> (new LCFault(msg), reason); } }