public async Task <ActionResult <BaseResponse <Food> > > CreateFood(CreateFoodCommand command) { try { var result = await _mediator.Send(command); return(Ok(result)); } catch (ValidationException ex) { var err = new BaseResponse <Food> (); err.Status = ResponseType.Error; err.Message = ex.Message; err.Content = null; return(Ok(err)); } }
public async Task <BaseResponse <Food> > Handle(CreateFoodCommand request, CancellationToken cancellationToken) { var response = new BaseResponse <Food> { ReponseName = nameof(CreateFoodCommand), Content = new List <Food> () { } }; var entity = _mapper.Map <Food> (request); var newentity = await _foodRepository.AddAsync(entity); if (newentity == null) { response.Status = ResponseType.Error; response.Message = $"{nameof(Food)} could not be created."; response.Content = null; } else { response.Status = ResponseType.Success; response.Message = $"{nameof(Food)} created successfully."; response.Content.Add(newentity); } return(response); }
public async Task <IActionResult> CreateFood(CreateFoodCommand command) { return(Ok(await _mediator.Send(command))); }
public async Task <ActionResult <int> > Create(CreateFoodCommand command) { return(await Mediator.Send(command)); }