Example #1
0
        public bool AddProductToOrderInfo(int count, Product product, Order order)
        {
            try
            {
                OrderInfo info = db.OrderInfoes.Where(x => x.OrderID == order.Id).Where(x => x.ProductID == product.Id).FirstOrDefault();
                if (info == null)
                {
                    info = db.OrderInfoes.Add(new OrderInfo
                    {
                        OrderID   = order.Id,
                        ProductID = product.Id,
                        Count     = count,
                        Total     = product.Cost * count,
                        Cost      = product.Cost
                    });
                    db.Entry(info).State = System.Data.Entity.EntityState.Added;

                    order.Price           = info.Total;
                    db.Entry(order).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                else
                {
                    info.Cost   = product.Cost;
                    info.Count += count;
                    info.Total  = product.Cost * info.Count;
                    db.OrderInfoes.Attach(info);

                    order.Price           = info.Total;
                    db.Entry(order).State = System.Data.Entity.EntityState.Modified;
                    db.Entry(info).State  = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
                this.CalOrder(order);
                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
            return(false);
        }
Example #2
0
 public void Update(User user)
 {
     db.Users.Attach(user);
     db.Entry(user).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
Example #3
0
 public void Update(Category category)
 {
     db.Categories.Attach(category);
     db.Entry(category).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
Example #4
0
 public void Update(Product product)
 {
     db.Products.Attach(product);
     db.Entry(product).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }
Example #5
0
 public void Update(Table table)
 {
     db.Tables.Attach(table);
     db.Entry(table).State = System.Data.Entity.EntityState.Modified;
     db.SaveChanges();
 }