Exemplo n.º 1
0
        public ActionResult Transfer()
        {
            int EmployeeId = (int)Session.Contents["EmployeeId"];
            var m = new Models.Inventory_.Transfer.ViewModel();

            using (var db = new dbEntities())
            {
                var ps = db.Products;
                var ls = db.EmployeeLocations.Where(el => el.EmployeeId == EmployeeId).Select(el => el.Location);

                foreach (var l in ls)
                {
                    var lm = new Models.Inventory_.Transfer.LocationModel();
                    lm.Id = l.Id;
                    lm.Name = l.Name;
                    foreach (var p in ps)
                    {
                        var pm = new Models.Inventory_.Transfer.ProductModel();
                        pm.Id = p.Id;
                        pm.Name = p.Name;
                        pm.OldQuantity = p.Inventories.SingleOrDefault(i => i.Location == l).Quantity;
                        pm.Quantity = pm.OldQuantity;
                        lm.Inventory.Add(pm);
                    }
                    m.Locations.Add(lm);
                }
            }

            return View(m);
        }
Exemplo n.º 2
0
        public ActionResult Transfer()
        {
            int EmployeeId = (int)Session.Contents["EmployeeId"];
            var m          = new Models.Inventory_.Transfer.ViewModel();

            using (var db = new dbEntities())
            {
                var ps = db.Products;
                var ls = db.EmployeeLocations.Where(el => el.EmployeeId == EmployeeId).Select(el => el.Location);

                foreach (var l in ls)
                {
                    var lm = new Models.Inventory_.Transfer.LocationModel();
                    lm.Id   = l.Id;
                    lm.Name = l.Name;
                    foreach (var p in ps)
                    {
                        var pm = new Models.Inventory_.Transfer.ProductModel();
                        pm.Id          = p.Id;
                        pm.Name        = p.Name;
                        pm.OldQuantity = p.Inventories.SingleOrDefault(i => i.Location == l).Quantity;
                        pm.Quantity    = pm.OldQuantity;
                        lm.Inventory.Add(pm);
                    }
                    m.Locations.Add(lm);
                }
            }

            return(View(m));
        }
Exemplo n.º 3
0
        public ActionResult Transfer(Models.Inventory_.Transfer.ViewModel m)
        {
            if (ModelState.IsValid)
            {
                using (var db = new dbEntities())
                {
                    foreach (var lm in m.Locations)
                    {
                        foreach (var pm in lm.Inventory)
                        {
                            db.Inventories.Single(i => i.LocationId == lm.Id && i.ProductId == pm.Id).Quantity = pm.Quantity;
                        }
                    }
                    db.SaveChanges();
                }

                return(RedirectToAction("Transfer", "Inventory"));
            }
            return(View(m));
        }