public async Task <IActionResult> Create([FromBody, CustomizeValidator] DishToAdd dish, CancellationToken cancellationToken = default) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var result = await _dishService.AddAsync(dish, cancellationToken); return(result.IsError ? throw new InvalidOperationException(result.Message) : result.IsSuccess ? (IActionResult)Ok(result.Data) //: BadRequest(new ProblemDetails() { // Detail = result.Message }); : StatusCode(StatusCodes.Status400BadRequest, result.Message)); } catch (InvalidOperationException ex) { Log.Error(ex, ex.Message); return(StatusCode(StatusCodes.Status500InternalServerError, new CustumResult() { Status = StatusCodes.Status500InternalServerError, Message = ex.Message })); } }
public async Task <ActionResult> Add(DishDto dish) { await _dishService.AddAsync(dish); return(Ok(dish)); }