public bool AddProduct(string ProductName, string ProductDesc, string ProductDetail, string ProductPrice, string ProductReview, int Stock, string Gift, string Sale, string vendor, Boolean onsale, string oldprice, string ProductImagePath1, string ProductImagePath2, string ProductImagePath3, string ProductImagePath4, Boolean show, List<string> cat_id) { var myProduct = new Product(); myProduct.ProductName = ProductName; myProduct.Description = ProductDesc; myProduct.Detail = ProductDetail; myProduct.Price = Double.Parse(ProductPrice); myProduct.Review = ProductReview; myProduct.StockID = Stock; myProduct.Gift = Gift; myProduct.Sale = Sale; myProduct.Vendor = vendor; myProduct.onSale = onsale; if (oldprice != "") myProduct.oldPrice = Double.Parse(oldprice); myProduct.ImagePath1 = ProductImagePath1; myProduct.ImagePath2 = ProductImagePath2; myProduct.ImagePath3 = ProductImagePath3; myProduct.ImagePath4 = ProductImagePath4; myProduct.Show = show; using (eWorldEntities db = new eWorldEntities()) { // Add product to DB. db.Products.Add(myProduct); foreach (string id in cat_id) { var cat = new ProductInCategory(); cat.CategoryID = Convert.ToInt32(id); myProduct.ProductID = myProduct.ProductID; db.ProductInCategories.Add(cat); } db.SaveChanges(); } // Success. return true; }
public void editProduct(Product myProduct, string ProductName, string ProductDesc, string ProductDetail, string ProductPrice, string ProductReview, int Stock, string Gift, string Sale, string vendor, Boolean onsale, string oldprice, string ProductImagePath1, string ProductImagePath2, string ProductImagePath3, string ProductImagePath4, Boolean show, List<string> cat_id) { myProduct.ProductName = ProductName; myProduct.Description = ProductDesc; myProduct.Detail = ProductDetail; myProduct.Price = Double.Parse(ProductPrice); myProduct.Review = ProductReview; myProduct.StockID = Stock; myProduct.Gift = Gift; myProduct.Sale = Sale; myProduct.Vendor = vendor; myProduct.onSale = onsale; if (oldprice != "") myProduct.oldPrice = Double.Parse(oldprice); myProduct.ImagePath1 = ProductImagePath1; myProduct.ImagePath2 = ProductImagePath2; myProduct.ImagePath3 = ProductImagePath3; myProduct.ImagePath4 = ProductImagePath4; myProduct.Show = show; }