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);
        }
예제 #2
0
        /// <inheritdoc />
        public async Task <IEnumerable <FoodDto> > GetAllAsync()
        {
            var entities = await _repo.GetAllAsync();

            var dtos = _mapper.Map <IEnumerable <FoodDto> >(entities);

            return(dtos);
        }
예제 #3
0
        public async Task <ActionResult <IEnumerable <FoodItemDto> > > GetAllAsync()
        {
            var foodItems = (await _foodRepository
                             .GetAllAsync())
                            .Select(record => record
                                    .ConvertToDto());

            return(Ok(foodItems));
        }
예제 #4
0
        // GET: Foods
        public async Task <IActionResult> Index()
        {
            var dbResult = await _foodRepository.GetAllAsync();

            if (!dbResult.Success || dbResult.Data == null)
            {
                return(NotFound());
            }

            return(View(dbResult.Data));
        }
예제 #5
0
 public async Task <IEnumerable <Food> > GetAsync()
 {
     return(await _foodRepository.GetAllAsync());
 }