private UserFunctionEntity CreateFuncEntity(UserFunctionEditDTO dto) { int sortNum = _userFunDal.GetMaxSortNum(dto.ParentID) + 1; int funcLevel = 1; if (dto.ParentID > 0) { var funcEntity = baseDal.Single(m => m.ID == dto.ParentID); funcLevel += funcEntity.FuncLevel; } UserFunctionEntity entity = new UserFunctionEntity(); entity = Mapper.DynamicMap <UserFunctionEntity>(dto); entity.SortNum = sortNum; entity.FuncLevel = funcLevel; entity.FuncStatus = Enum.User.UserFuncStatusEnum.Valid; entity.AreaName = entity.AreaName ?? string.Empty; entity.ControllerName = entity.ControllerName ?? string.Empty; entity.ActionName = entity.ActionName ?? string.Empty; return(entity); }
public UserFunctionEditDTO GetFunctionEditDTO(long funcID, long parentID) { UserFunctionEditDTO dto = new UserFunctionEditDTO(); var allFuncs = GetAllFromCache(); var funcIDList = new List <long>() { funcID, parentID }; var list = allFuncs.Where(m => funcIDList.Contains(m.ID)); var parentFuncEntity = list.FirstOrDefault(m => m.ID == parentID); var funcEntity = list.FirstOrDefault(m => m.ID == funcID); if (funcEntity != null) { dto = Mapper.DynamicMap <UserFunctionEditDTO>(funcEntity); dto.CanDeleteFunc = true; } if (parentFuncEntity != null) { dto.ParentID = parentFuncEntity.ID; dto.ParentFuncTitle = parentFuncEntity.FucTitle; } else { dto.ParentID = 0; dto.ParentFuncTitle = "根节点"; } return(dto); }
public ExecuteResult AddOrEditFunction(UserFunctionEditDTO dto) { ExecuteResult result = new ExecuteResult() { IsSuccess = true }; long funcID = dto.ID; UserFunctionEntity funEntity = CreateFuncEntity(dto); if (funcID > 0) { baseDal.Update(funEntity, m => m.ID == funcID); } else { baseDal.Add(funEntity); } return(result); }
public ActionResult AjaxAddOrEditFunction(UserFunctionEditDTO dto) { var result = _funcService.AddOrEditFunction(dto); return(Json(result, JsonRequestBehavior.AllowGet)); }