public async Task <ActionResult <Dish> > UpdateDish(Dish dish) { var updateCommand = new UpdateDishCommand(dish); var response = await _mediator.Send(updateCommand); return(Ok(response)); }
public async Task <DishResponseModel> Handle(UpdateDishCommand request, CancellationToken cancellationToken) { var existedDish = await _dishRepository.GetByIdAsync(request.Id); if (existedDish == null) { throw new Exception($"Dish with id {request.Id} does not exist"); } existedDish.Update(request.Name, request.Description, request.PhotoPath); await _dishRepository.Update(existedDish); var response = existedDish.Adapt <DishResponseModel>(); return(response); }
public async Task <IActionResult> UpdateAsync([FromBody] UpdateDishCommand command) { var response = await _mediator.Send(command); return(JsonResult(response)); }