public IActionResult SaveEntity(FoodCategory entity) { bool result = true; string message = string.Empty; var userEmail = User.GetSpecificClaim("Email"); if (ModelState.IsValid) { entity.UserModified = userEmail; if (entity.Id == 0) { entity.UserCreated = userEmail; _foodCategoryService.Add(entity, out result, out message); } else { _foodCategoryService.UpdateChangedProperties(entity, out result, out message); } return(new OkObjectResult(new GenericResult(result, message))); } else { List <string> listErrors = ModelState.Values.SelectMany(v => v.Errors).Select(x => x.ErrorMessage).ToList(); string errorString = String.Join("\n", listErrors.ToArray()); return(new OkObjectResult(new GenericResult(false, errorString))); } }
public async Task <IActionResult> Create([FromBody] FoodCategoryCreateRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState.GetErrorMessages())); } try { var response = await _foodCategorySerive.Add(request); return(Ok(response)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }