Esempio n. 1
0
        public bool EditItem(Item item, bool UpdateStock = true)
        {
            using (var db = new InventorySystemContext())
            {
                int change = 0;
                var old    = db.Items.First(i => i.ID == item.ID).Quantity;
                change = item.Quantity - old;

                if (change != 0 && UpdateStock)
                {
                    Transaction transaction = new Transaction()
                    {
                        Change = change,
                        Item   = item,
                        Reason = "Stock Updated",
                        Time   = DateTime.Now
                    };
                    AddItem(item, transaction);
                }

                db.SaveChanges();
            }
            using (var db = new InventorySystemContext())
            {
                db.Entry(item).State = System.Data.Entity.EntityState.Modified;
                //db.Items.Add(item);

                db.SaveChanges();
            }
            return(true);
        }