コード例 #1
0
        private async Task <List <ProductDetailData> > CreateProductDetailDataAsync(Product product, List <LineItemDetailData> lineItemList)
        {
            List <ProductDetailData> resultList  = new List <ProductDetailData>();
            Task <List <Spec> >      specList    = _oc.Products.ListAllSpecsAsync(product.ID);
            Task <List <Variant> >   variantList = _oc.Products.ListAllVariantsAsync(product.ID);
            await Task.WhenAll(specList, variantList);

            Supplier supplier = new Supplier();

            try
            {
                supplier = await _oc.Suppliers.GetAsync(product.DefaultSupplierID);
            }
            catch (Exception ex)
            {
                LogFailure(ex.Message);
            }

            if (product.Inventory != null && product.Inventory.VariantLevelTracking)
            {
                foreach (Variant variant in variantList.Result)
                {
                    ProductDetailData data = new ProductDetailData()
                    {
                        ProductID    = product.ID,
                        PartitionKey = "PartitionValue",
                        ProductSales = GetProductSales(product.ID, lineItemList),
                        Product      = product,
                        Data         = await FlattenProductDataDetailAsync(product, supplier, variant)
                    };
                    resultList.Add(data);
                }
            }
            else
            {
                resultList.Add(new ProductDetailData
                {
                    ProductID    = product.ID,
                    PartitionKey = "PartitionValue",
                    ProductSales = GetProductSales(product.ID, lineItemList),
                    Product      = product,
                    Data         = await FlattenProductDataDetailAsync(product, supplier)
                });
            }

            return(resultList);
        }
コード例 #2
0
        //H
        public IActionResult UpdateProduct()
        {
            if (!IsAdmin())
            {
                return(View(index));
            }
            bool       check        = false;
            string     productIDStr = Request.Form["txtProductID"];
            int        productID    = Int32.Parse(productIDStr);
            string     priceStr     = Request.Form["txtProductPrice"];
            double     price        = Double.Parse(priceStr);
            string     color        = Request.Form["txtProductColor"];
            ProductDTO proDto       = new ProductDTO
            {
                ProductId = productID,
                Color     = color,
                Price     = price
            };

            if (check = new ProductData().UpdateProductById(proDto))
            {
                string[] size                = Request.Form["txtSize"];
                string[] quantity            = Request.Form["txtQuantity"];
                List <ProductDetailDTO> list = new List <ProductDetailDTO>();
                ProductDetailDTO        detailDto;
                for (int i = 0; i < size.Length; i++)
                {
                    detailDto = new ProductDetailDTO
                    {
                        ProductId = productID,
                        Quantity  = Int32.Parse(quantity[i]),
                        Size      = Int32.Parse(size[i])
                    };
                    list.Add(detailDto);
                }
                if (check = new ProductDetailData().UpdateQuantityByProductDTO(list))
                {
                    string[] newSize     = Request.Form["txtNewSize"];
                    string[] newQuantity = Request.Form["txtNewQuantity"];
                    if (newSize != null && newQuantity != null)
                    {
                        List <ProductDetailDTO> newList = new List <ProductDetailDTO>();
                        ProductDetailDTO        newDetailDto;
                        for (int i = 0; i < newSize.Length; i++)
                        {
                            newDetailDto = new ProductDetailDTO
                            {
                                ProductId = productID,
                                Quantity  = Int32.Parse(newQuantity[i]),
                                Size      = Int32.Parse(newSize[i])
                            };
                            newList.Add(newDetailDto);
                        }
                        check = new ProductDetailData().AddProductDetailsByProductDTO(newList);
                    }
                }
            }
            if (check)
            {
                ViewBag.Successful = "Update successfully!";
            }
            else
            {
                ViewBag.Failed = "Update failed!";
            }

            return(View("ProductManager"));
        }