예제 #1
0
        public ActionResult Sell(_5Bites.Models.Store_.Sell.ViewModel m)
        {
            if (ModelState.IsValid)
            {
                int EmployeeId = (int)Session.Contents["EmployeeId"];

                using (var db = new dbEntities())
                {
                    foreach (var sm in m.Stores)
                    {
                        var s = db.Stores.Single(s_ => s_.Id == sm.Id);
                        foreach (var pm in sm.Inventory.Where(pm => pm.QuantitySold != 0))
                        {
                            var t = new Transaction();
                            t.ProductId = pm.Id;
                            t.StoreId = sm.Id;
                            t.EmployeeId = EmployeeId;
                            t.Quantity = pm.QuantitySold;
                            t.Timestamp = DateTime.Now;
                            db.Transactions.Add(t);

                            s.Location.Inventories.Single(i => i.ProductId == pm.Id).Quantity -= pm.QuantitySold;
                        }
                        s.Bank += sm.Inventory.Sum(pm => pm.QuantitySold * pm.Price);
                    }
                    db.SaveChanges();
                }

                return RedirectToAction("Sell", "Store");
            }
            return View(m);
        }
예제 #2
0
 public ActionResult ConfirmSale(_5Bites.Models.Store_.Sell.ViewModel m)
 {
     if (ModelState.IsValid)
     {
         return View(m);
     }
     return View("Sell", m);
 }