コード例 #1
0
        public ActionResult ItemsOut()
        {
            if (Session["isAdmin"] == null || !(bool)Session["isAdmin"])
                return RedirectToAction("Index", new { controller = "Home", action = "Index" });
            var allItems = db.Items.Where(item => item.CheckedOutById != null);         //Items checked out or returned
            var checkedOutItems = allItems.Where(item => item.CheckedInById == null).OrderBy(item => item.ItemType.ItemName).ThenBy(item => item.Label!=null? item.Label.LabelName : "");  //Items checked out
            if (checkedOutItems.ToList().Count == 0)
            {
                TempData["error"] = "No items are currently checked out";
                return RedirectToAction("Index");
            }

            IList<SelectListItem> inventoryLocations = db.InventoryLocations.Select(x => new SelectListItem
            {
                Text = x.InventoryLocationName,
                Value = x.InventoryLocationId.ToString()
            }).OrderBy(listItem => listItem.Text).ToList();

            IList<bool> lostItems = new List<bool>();
            IList<bool> returnedItems = new List<bool>();
            IList<string> schoolDisplayStrings = new List<string>();
            foreach (var item in checkedOutItems)
            {
                int checkedOutId = (int)item.CheckedOutSchoolId;
                var school = db.Schools.Where(schoolMatch => schoolMatch.SchoolId == checkedOutId).ToList();
                if (school.Count>0)
                    schoolDisplayStrings.Add(school[0].SchoolName);
                lostItems.Add(false);
                returnedItems.Add(false);
            }
            ItemsOutViewModel vm = new ItemsOutViewModel
            {
                CheckedOutItems = checkedOutItems.ToList(),
                SchoolDisplayStrings = schoolDisplayStrings,
                ItemsLost = lostItems,
                ItemReturn = returnedItems
            };
            return View(vm);
        }
コード例 #2
0
        public ActionResult ItemsOut(ItemsOutViewModel vm)
        {
            if (Session["isAdmin"] == null || !(bool)Session["isAdmin"])
                return RedirectToAction("Index", new { controller = "Home", action = "Index" });
            if (vm == null || vm.ItemsLost == null || vm.ItemReturn == null)
                return RedirectToAction("Index");

            if(!CheckReturnedAndLost(vm.CheckedOutItems, vm.ItemsLost, vm.ItemReturn))
            {
                TempData["error"] = "An item cannot be marked as lost and returned";
                return RedirectToAction("Index");
            }
            if(!UpdateItems(vm.CheckedOutItems, vm.ItemsLost, vm.ItemReturn))
            {
                TempData["error"] = "Item not found, cannot continue";
                return RedirectToAction("Index");
            }
            return RedirectToAction("Index");
        }