public void Update(SpreadsheetProductViewModel product)
        {
            var entity = new Product();

            entity.ProductID    = product.ProductID;
            entity.ProductName  = product.ProductName;
            entity.UnitPrice    = product.UnitPrice;
            entity.UnitsInStock = (short)product.UnitsInStock;
            entity.Discontinued = product.Discontinued;

            entities.Products.Attach(entity);
            entities.Entry(entity).State = EntityState.Modified;
            entities.SaveChanges();
        }
        public void Destroy(SpreadsheetProductViewModel product)
        {
            var entity = new Product();

            entity.ProductID = product.ProductID;

            entities.Products.Attach(entity);

            entities.Products.Remove(entity);

            var orderDetails = entities.OrderDetails.Where(pd => pd.ProductID == entity.ProductID);

            foreach (var orderDetail in orderDetails)
            {
                entities.OrderDetails.Remove(orderDetail);
            }

            entities.SaveChanges();
        }
        public void Create(SpreadsheetProductViewModel product)
        {
            var entity = new Product();

            entity.ProductName  = product.ProductName;
            entity.UnitPrice    = product.UnitPrice;
            entity.UnitsInStock = (short)product.UnitsInStock;
            entity.Discontinued = product.Discontinued;

            if (entity.CategoryID == null)
            {
                entity.CategoryID = 1;
            }

            entities.Products.Add(entity);
            entities.SaveChanges();

            product.ProductID = entity.ProductID;
        }