public async Task <IActionResult> CreateFunctionAsync([FromBody] FunctionCreateModel model) { if (string.IsNullOrWhiteSpace(model.Code)) { throw new IsRequiredException("code"); } if (model.Code.Length > 20) { throw new CodeIsInvalidException(); } if (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 (await _functionRepository.AnyByDescriptionAsync(model.Description)) { throw new AlreadyExistsException("description"); } DateTime now = DateTime.Now; var function = new Function { Code = model.Code, Description = model.Description, CreatedDate = now, CreatedBy = CurrentAccountId, UpdatedDate = now, UpdatedBy = CurrentAccountId }; await _functionRepository.CreateFunctionAsync(function); return(Ok(FunctionDTO.GetFrom(function))); }