public async Task <BaseResponse <Dietician> > Handle(CreateDieticianCommand request, CancellationToken cancellationToken) { var response = new BaseResponse <Dietician> { ReponseName = nameof(CreateDieticianCommand), Content = new List <Dietician> () { } }; var entity = _mapper.Map <Dietician> (request); var newentity = await _dieticianRepository.AddAsync(entity); if (newentity == null) { response.Status = ResponseType.Warning; response.Message = $"{nameof(Dietician)} could not be created."; response.Content = null; } else { response.Status = ResponseType.Success; response.Message = $"{nameof(Dietician)} created successfully."; response.Content.Add(newentity); } return(response); }
public async Task <ActionResult <BaseResponse <Dietician> > > CreateDietician(CreateDieticianCommand 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)); } }