public async Task <ActionResult <BaseResponse <Food> > > GetFoods() { var query = new GetListFoodQuery(); var result = await _mediator.Send(query); return(Ok(result)); }
public async Task <BaseResponse <Food> > Handle(GetListFoodQuery request, CancellationToken cancellationToken) { var response = new BaseResponse <Food> () { ReponseName = nameof(GetListFoodQuery), Content = new List <Food> () { } }; var entity = await _foodRepository.GetAllAsync(); entity = _mapper.Map <List <Food> > (entity); if (entity == null) { response.Status = ResponseType.Error; response.Message = $"{nameof(Food)} not found."; response.Content = null; } else { response.Status = ResponseType.Success; response.Message = $"{nameof(Food)} get successfully."; response.Content.AddRange(entity); } return(response); }