コード例 #1
0
        public async Task <ActionResult <IEnumerable <ProductDetailSpecificationViewModel> > > GetAllAsync()
        {
            List <ProductDetailSpecificationViewModel> productDetailSpecifications = new List <ProductDetailSpecificationViewModel>();
            List <ProductViewModel> products = await _productQueries.FindAllAsync();

            for (int i = 0; i < products.Count; i++)
            {
                ProductDetailSpecificationViewModel productSpecifications = new ProductDetailSpecificationViewModel();

                productSpecifications.ProductId          = products[i].Id;
                productSpecifications.ProductName        = products[i].Name;
                productSpecifications.ProductPrice       = products[i].Price;
                productSpecifications.ProductDescription = products[i].Description;
                productSpecifications.ProductAmount      = products[i].Amount;
                productSpecifications.ProductColor       = products[i].Color;
                productSpecifications.ProductPhoto       = products[i].Photo;
                productSpecifications.ProductCreatedAt   = products[i].CreatedAt;
                productSpecifications.ProductUpdatedAt   = products[i].UpdatedAt;

                var category = await _queries.FindByCategoryAsync(products[0].Id);

                productSpecifications.CategoryId   = category.CategoryId;
                productSpecifications.CategoryName = category.CategoryName;

                //Get all specifications by product
                List <DetailSpecificationProductViewModel> productDetails = await _queries.FindAllByProductIdAsync(products[i].Id);

                //productSpecifications.Specifications = productDetails;
                productSpecifications.detailSpecificationsId = new List <int>();
                for (int j = 0; j < productDetails.Count; j++)
                {
                    productSpecifications.detailSpecificationsId.Add(productDetails[j].DetailSpecificationId);
                }

                productDetailSpecifications.Add(productSpecifications);
            }

            return(productDetailSpecifications);
        }
コード例 #2
0
 public async Task <ActionResult <IEnumerable <ProductViewModel> > > GetAllAsync()
 {
     return(await _queries.FindAllAsync());
 }