Esempio n. 1
0
        public async Task <ActionResult <Dish> > UpdateDish(Dish dish)
        {
            var updateCommand = new UpdateDishCommand(dish);
            var response      = await _mediator.Send(updateCommand);

            return(Ok(response));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        public async Task <IActionResult> UpdateAsync([FromBody] UpdateDishCommand command)
        {
            var response = await _mediator.Send(command);

            return(JsonResult(response));
        }