//Show All checked out items by the selected school public ActionResult Index(int? id) { if (Session["isAdmin"] == null) return RedirectToAction("Index", new { controller = "Home", action = "Index" }); if (id == null) return RedirectToAction("Index", new { Controller = "CheckOut", Action = "Index"}); int result = (int)id; var school = db.Schools.Find(id); if (school == null) { TempData["error"] = "Cannot find selected school"; return RedirectToAction("Index", new { Controller = "CheckOut", Action = "Index" }); } var rentedItems = getRentedItems(result); if(rentedItems.Count == 0) { TempData["error"] = "Selected School does not have items to be checked in"; return RedirectToAction("Index", new { Controller = "CheckOut", Action = "Index" }); } IList<ItemTypes> rentedItemTypes = new List<ItemTypes>(); IList<bool> rentedItemsTypesCheckboxes = new List<bool>(); foreach (var item in rentedItems) { int index = rentedItemTypes.IndexOf(item.ItemType); if (index == -1) { rentedItemTypes.Add(item.ItemType); rentedItemsTypesCheckboxes.Add(false); } } CheckInItemTypeSelectViewModel vm = new CheckInItemTypeSelectViewModel { ItemTypesModel = rentedItemTypes.OrderBy(itemType => itemType.ItemName).ToList(), ItemTypesCheckboxes = rentedItemsTypesCheckboxes, SelectedSchoolId = result }; return View(vm); }
public ActionResult ItemTypesSubmit(CheckInItemTypeSelectViewModel vm) { if (Session["isAdmin"] == null) return RedirectToAction("Index", new { controller = "Home", action = "Index" }); if (vm == null) return RedirectToAction("Index"); int index = 0; IList<ItemTypes> selectedItemTypes = new List<ItemTypes>(); IList<int> itemQuantities = new List<int>(); foreach(bool isChecked in vm.ItemTypesCheckboxes) { if (isChecked) { var itemType = db.ItemTypes.Find(vm.ItemTypesModel[index].ItemTypeId); if (itemType == null) return RedirectToAction("Index"); selectedItemTypes.Add(itemType); var itemsRented = db.Items.Where(item => item.CheckedOutSchoolId == vm.SelectedSchoolId); itemsRented = itemsRented.Where(item => item.ItemTypeId == itemType.ItemTypeId); itemsRented = itemsRented.Where(item => item.CheckedInById == null); int numRented = itemsRented.ToList().Count; itemQuantities.Add(numRented); } index++; } CheckInQuantitySelectViewModel quantityVm = new CheckInQuantitySelectViewModel { SelectedItemTypesModel = selectedItemTypes, ItemQuantityFields = itemQuantities, SelectedSchoolId = vm.SelectedSchoolId }; TempData["CheckInQuantitySelectViewModel"] = quantityVm; return RedirectToAction("QuantitySelect"); }