public IActionResult Update(string id) { var dal = new FunctionDal(); FunctionUpdateModel model = new FunctionUpdateModel(); model.Functions = dal.QueryParentOrderByName(); model.Pages = GetPages(); FunctionDefinition function = dal.Find(id); model.FunctionId = function.FunctionId; model.ParentId = function.ParentId; model.Name = function.Name; model.Icon = function.Icon; model.Page = function.Page; model.Display = function.Display; model.Postion = function.Postion; return(View(model)); }
public IActionResult Update(FunctionUpdateModel model) { var dal = new FunctionDal(); model.Functions = dal.QueryParentOrderByName(); FunctionDefinition function = dal.Find(model.FunctionId); function.ParentId = model.ParentId; function.Name = model.Name; function.Icon = model.Icon; function.Page = model.Page; function.Display = model.Display; function.Postion = model.Postion; try { dal.Update(function); return(Json(1)); } catch { ViewBag.Message = ""; return(Json(0)); } }
public async Task <IActionResult> UpdateFunctionAsync([FromRoute] int functionId, [FromBody] FunctionUpdateModel model) { var function = await _functionRepository.GetFunctionByIdAsync(functionId); if (function == null) { throw new NotFound404Exception("function"); } if (function.Code.Contains("Full")) { throw new ForbiddenException(); } if (string.IsNullOrWhiteSpace(model.Code)) { throw new IsRequiredException("code"); } if (model.Code.Length > 20) { throw new CodeIsInvalidException(); } if (function.Code != model.Code && await _functionRepository.AnyByCodeAsync(model.Code)) { throw new AlreadyExistsException("code"); } if (string.IsNullOrWhiteSpace(model.Description)) { throw new IsRequiredException("description"); } if (model.Description.Length < 20) { throw new DescriptionIsInvalidException(); } if (function.Description != model.Description && await _functionRepository.AnyByDescriptionAsync(model.Description)) { throw new AlreadyExistsException("description"); } // bind data function.Code = model.Code; function.Description = model.Description; function.IsActive = model.IsActive; function.UpdatedDate = DateTime.Now; await _functionRepository.UpdateFunctionAsync(function); return(Ok(FunctionDTO.GetFrom(function))); }