Esempio n. 1
0
        public async Task <ActionResult <IList <ShopDto> > > GetShops()
        {
            var query  = new GetShopsQuery();
            var result = await _mediator.Send(query);

            return(Ok(result));
        }
Esempio n. 2
0
        public async Task <IList <ShopDto> > Handle(GetShopsQuery request, CancellationToken cancellationToken)
        {
            var shops = await _repository.Read()
                        .Include(x => x.Company).ToListAsync();

            var shopsDto = _mapper.Map <IList <ShopDto> >(shops);

            return(shopsDto);
        }
Esempio n. 3
0
        public async Task <IEnumerable <GetShopDto> > Handle(GetShopsQuery request, CancellationToken cancellationToken)
        {
            var shops = repository.GetAll();
            List <GetShopDto> listShops = new List <GetShopDto>();

            foreach (var shop in shops)
            {
                List <int> ingredientsId = context.JoinIngredientShop
                                           .Where(p => p.ShopsId == shop.Id)
                                           .Select(p => p.IngredientsId)
                                           .ToList();
                GetShopDto shopDto = new GetShopDto()
                {
                    Id        = shop.Id,
                    Name      = shop.Name,
                    LocationX = shop.LocationX,
                    LocationY = shop.LocationY,
                };
                foreach (int i in ingredientsId)
                {
                    IngredientsFromShop ingredient = await context.Ingredients.FindAsync(i);

                    GetIngredientDto getIngredientDto = new GetIngredientDto();
                    getIngredientDto.Id    = ingredient.Id;
                    getIngredientDto.Name  = ingredient.Name;
                    getIngredientDto.Price = ingredient.Price;
                    //voi lua si cantitatea specifica ingredientului din shopul respectiv
                    int quantity = context.JoinIngredientShop
                                   .Where(p => (p.IngredientsId == ingredient.Id) && (p.ShopsId == shopDto.Id))
                                   .Select(p => p.Quantity)
                                   .FirstOrDefault();
                    getIngredientDto.Quantity = quantity;
                    shopDto.Ingredients.Add(getIngredientDto);
                }
                listShops.Add(shopDto);
            }
            return(listShops);
        }
Esempio n. 4
0
 public Task <IAsyncEnumerable <Core.Models.Shop> > Handle(
     GetShopsQuery request,
     CancellationToken cancellationToken)
 {
     return(Task.FromResult(_store.GetShops(shop => shop)));
 }
 public async Task <IEnumerable <ShopDto> > Handle(GetShopsQuery request, CancellationToken cancellationToken)
 {
     return(await _shopService.GetAllAsync());
 }