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