Beispiel #1
0
 public void AddImagesToProduct(VM.Product product)
 {
     foreach (var img in product.Images)
     {
         var productImage = new DM.ProductImage()
         {
             ProductID = product.ProductID,
             Image     = img
         };
         dbContext.ProductImages.Add(productImage);
     }
     dbContext.SaveChanges();
 }
Beispiel #2
0
        public void Add(VM.Product product)
        {
            var prod = new DM.Product()
            {
                CategoryID         = product.CategoryID,
                SubCategoryID      = product.SubcategoryID,
                ProductDescription = product.ProductDescription,
                Color              = product.Color,
                UnitPrice          = product.UnitPrice,
                ProductName        = product.ProductName,
                DiscountPercentage = product.DiscountPercentage
            };
            var insertedProduct = dbContext.Products.Add(prod);

            foreach (var s in product.Stocks)
            {
                var stock = new DM.Stock()
                {
                    SizeID    = s.SizeID,
                    ProductID = insertedProduct.ProductID,
                    Quantity  = s.Quantity
                };
                dbContext.Stocks.Add(stock);
                //dbContext.SaveChanges();
            }
            foreach (var img in product.Images)
            {
                var productImage = new DM.ProductImage()
                {
                    ProductID = insertedProduct.ProductID,
                    Image     = img
                };
                dbContext.ProductImages.Add(productImage);
                //dbContext.SaveChanges();
            }
            dbContext.SaveChanges();
        }