예제 #1
0
        public async Task <IActionResult> StoreDetails(Guid id)
        {
            StoreDTO storeDTO = new StoreDTO();

            Store store = await _storesRepository.GetById(id);

            storeDTO.Name        = store.Name;
            storeDTO.Description = store.Description;
            storeDTO.Website     = store.Website;

            List <ProductDTO>          productDTOs   = new List <ProductDTO>();
            IEnumerable <ProductStore> productStores = await _productStoresRepository.GetByStore(id);

            foreach (var productStore in productStores)
            {
                Product product = await _productsRepository.GetById(productStore.ProductId);

                ProductDTO productDTO = new ProductDTO
                {
                    Name              = product.Name,
                    Brand             = product.Brand,
                    Quantity          = product.Quantity,
                    UnitOfMeasurement = product.UnitOfMeasurement
                };
                productDTOs.Add(productDTO);
            }

            storeDTO.Products = productDTOs;

            return(Ok(storeDTO));
        }
        public async Task <IActionResult> ProductDetails(Guid id)
        {
            ProductDTO productDTO = new ProductDTO();

            Product product = await _productsRepository.GetById(id);

            IEnumerable <ProductStore> productStore = await _productStoresRepository.GetByProduct(product.Id);


            productDTO.Name              = product.Name;
            productDTO.Quantity          = product.Quantity;
            productDTO.Brand             = product.Brand;
            productDTO.UnitOfMeasurement = product.UnitOfMeasurement;

            List <PriceInfoDTO> prices = new List <PriceInfoDTO>();

            foreach (var price in productStore)
            {
                Store store = await _storesRepository.GetById(price.StoreId);

                PriceInfoDTO priceInfoDTO = new PriceInfoDTO()
                {
                    Price     = price.Price,
                    StoreName = store.Name
                };
                prices.Add(priceInfoDTO);
            }
            prices.OrderBy(x => x.Price);
            productDTO.Prices = prices;

            return(Ok(productDTO));
        }