public async Task <BaseResponse <DietMethod> > Handle(UpdateDietMethodCommand request, CancellationToken cancellationToken) { var response = new BaseResponse <DietMethod> () { ReponseName = nameof(UpdateDietMethodCommand), Content = new List <DietMethod> () { } }; var entity = await _dietMethodRepository.GetOneAsync(p => p.Id == request.Id); if (entity == null) { response.Status = ResponseType.Error; response.Message = $"{nameof(DietMethod)} not found."; response.Content = null; } else { _mapper.Map(request, entity, typeof(UpdateDietMethodCommand), typeof(DietMethod)); await _dietMethodRepository.UpdateAsync(entity); response.Status = ResponseType.Success; response.Message = $"{nameof(DietMethod)} updated successfully."; response.Content.Add(entity); } return(response); }
public async Task <ActionResult <BaseResponse <DietMethod> > > UpdateDietMethod(UpdateDietMethodCommand command) { try { var result = await _mediator.Send(command); return(Ok(result)); } catch (ValidationException ex) { var err = new BaseResponse <DietMethod> (); err.Status = ResponseType.Error; err.Message = ex.Message; err.Content = null; return(Ok(err)); } }