public void SavePrice(Price price)
 {
     if (price.PriceID == 0)
     {
         context.Prices.Add(price);
     }
     else
     {
         context.Entry(price).State = EntityState.Modified;
     }
     context.SaveChanges();
 }
 public void SaveVendor(Vendor vendor)
 {
     if (vendor.VendorID == 0)
     {
         context.Vendors.Add(vendor);
     }
     else
     {
         context.Entry(vendor).State = EntityState.Modified;
     }
     context.SaveChanges();
 }
예제 #3
0
        public void SaveStatistic(Statistic statistic)
        {
            if (statistic.StatisticID == 0)
            {
                context.Statistics.Add(statistic);
            }
            else
            {
                context.Entry(statistic).State = EntityState.Modified;
            }

            context.SaveChanges();
        }
예제 #4
0
        public void SaveProduct(Product product)
        {
            Product productOrigin = context.Products.FirstOrDefault(x => x.Code == product.Code);

            if (productOrigin == null)
            {
                //
                product.CreationDate = DateTime.Now.Date;
                context.Products.Add(product);
                context.SaveChanges();
            }
            else
            {
                //  context.Entry(productOrigin).State = EntityState.Detached;
                //context.Products.Attach(productOrigin);
                if (!productOrigin.Equals(product))
                {
                    productOrigin.CloneProduct(product);
                    context.Entry(productOrigin).State = EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }