public void SaveProduct(Product product)
        {
            if (product.ProductID == 0)
            {
                context.Products.Add(product);
            }
            else
            {
                if (product.CategoryID != product.Category.CategoryID)
                {
                    product.Category.CategoryID = product.CategoryID;
                }

                context.Entry(product).State = System.Data.EntityState.Modified;
            }

            context.SaveChanges();
        }
示例#2
0
        public void SaveProduct(Entities.Product product)
        {
            if (product.ProductID == 0)
            {
                context.Products.Add(product);
            }
            else
            {
                Product prodToUpdate = context.Products
                                       .Where(p => p.ProductID == product.ProductID).FirstOrDefault();

                if (prodToUpdate != null)
                {
                    context.Entry(prodToUpdate).CurrentValues.SetValues(product);
                }
            }

            context.SaveChanges();
        }
示例#3
0
 public bool SaveProduct(Product product)
 {
     try
     {
         if (product.ProductID <= 0)
         {
             context.Products.Add(product);
         }
         else
         {
             var forRefresh = context.Products.Find(product.ProductID);
             if (forRefresh != null)
             {
                 context.Entry(forRefresh).CurrentValues.SetValues(product);
             }
         }
         context.SaveChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
示例#4
0
 public bool Update(TEntity entity)
 {
     Context.Entry(entity).State = EntityState.Modified;
     return(Context.SaveChanges() > 0);
 }
示例#5
0
 public void Edit(Customer cust)
 {
     context.Entry(cust).State = EntityState.Modified;
     context.SaveChanges();
 }