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