Ejemplo n.º 1
0
        public void SaveProduct(Product product)
        {
            using (DB db = new DB()){
                //see if the product is in the system
                Commerce.Data.SqlRepository.Product dbProduct =
                    db.Products.Where(x => x.ProductID == product.ID).SingleOrDefault();
                bool isNew = false;
                if (dbProduct == null)
                {
                    dbProduct = new Commerce.Data.SqlRepository.Product();
                    isNew     = true;
                }
                else
                {
                    //remove them for refresh
                    //wish there was a better way to do this but...
                    db.ProductDescriptors.DeleteAllOnSubmit(from pd in db.ProductDescriptors where pd.ProductID == product.ID select pd);
                }

                //add the descriptors
                foreach (ProductDescriptor pd in product.Descriptors)
                {
                    Commerce.Data.SqlRepository.ProductDescriptor dbPd = new Commerce.Data.SqlRepository.ProductDescriptor();
                    dbPd.ProductID = product.ID;
                    dbPd.Title     = pd.Title;
                    dbPd.Body      = pd.Body;
                    dbProduct.ProductDescriptors.Add(dbPd);
                }

                //some left/right
                dbProduct.AllowBackOrder    = product.AllowBackOrder;
                dbProduct.BaseUnitPrice     = product.Price;
                dbProduct.DeliveryMethodID  = (int)product.Delivery;
                dbProduct.DiscountPercent   = product.DiscountPercent;
                dbProduct.EstimatedDelivery = product.EstimatedDelivery;
                dbProduct.InventoryStatusID = (int)product.Inventory;
                dbProduct.Manufacturer      = product.Manufacturer;
                dbProduct.ProductCode       = product.ProductCode;
                dbProduct.ProductName       = product.Name;
                dbProduct.WeightInPounds    = product.WeightInPounds;



                if (isNew)
                {
                    db.Products.InsertOnSubmit(dbProduct);
                }


                db.SubmitChanges();
            }
        }
		private void detach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.InventoryStatus = null;
		}
		private void detach_Products(Product entity)
		{
			this.SendPropertyChanging();
			entity.DeliveryMethod = null;
		}
 partial void DeleteProduct(Product instance);
 partial void UpdateProduct(Product instance);
 partial void InsertProduct(Product instance);
        public void SaveProduct(Product product) {
            
            using(DB db=new DB()){
                
                //see if the product is in the system
                Commerce.Data.SqlRepository.Product dbProduct = 
                    db.Products.Where(x => x.ProductID == product.ID).SingleOrDefault();
                bool isNew = false;
                if (dbProduct == null) {
                    dbProduct = new Commerce.Data.SqlRepository.Product();
                    isNew = true;
                }
                else {
                    //remove them for refresh
                    //wish there was a better way to do this but...
                    db.ProductDescriptors.DeleteAllOnSubmit(from pd in db.ProductDescriptors where pd.ProductID == product.ID select pd);
                }

                //add the descriptors
                foreach (ProductDescriptor pd in product.Descriptors) {
                    Commerce.Data.SqlRepository.ProductDescriptor dbPd = new Commerce.Data.SqlRepository.ProductDescriptor();
                    dbPd.ProductID = product.ID;
                    dbPd.Title = pd.Title;
                    dbPd.Body = pd.Body;
                    dbProduct.ProductDescriptors.Add(dbPd);
                }

                //some left/right
                dbProduct.AllowBackOrder = product.AllowBackOrder;
                dbProduct.BaseUnitPrice = product.Price;
                dbProduct.DeliveryMethodID = (int)product.Delivery;
                dbProduct.DiscountPercent = product.DiscountPercent;
                dbProduct.EstimatedDelivery = product.EstimatedDelivery;
                dbProduct.InventoryStatusID = (int)product.Inventory;
                dbProduct.Manufacturer = product.Manufacturer;
                dbProduct.ProductCode = product.ProductCode;
                dbProduct.ProductName = product.Name;
                dbProduct.WeightInPounds = product.WeightInPounds;
                


                if (isNew)
                    db.Products.InsertOnSubmit(dbProduct);


                db.SubmitChanges();
            
            }
        }