public ActionResult QuantitySubmit(CheckInQuantitySelectViewModel vm) { if (Session["isAdmin"] == null) return RedirectToAction("Index", new { controller = "Home", action = "Index" }); if (vm == null) return RedirectToAction("Index"); var school = db.Schools.Find(vm.SelectedSchoolId); if (school == null) return RedirectToAction("Index", new { Controller = "CheckOut", Action = "Index" }); IList<Items> itemsToReturn = new List<Items>(); IList<string> itemDisplayString = new List<string>(); IList<string> itemDisplayLabels = new List<string>(); var rentedItems = getRentedItems(vm.SelectedSchoolId); int index = 0; foreach(int quantity in vm.ItemQuantityFields) { if(quantity > 0) { var potentialItems = rentedItems.Where(item => item.ItemTypeId == vm.SelectedItemTypesModel[index].ItemTypeId).ToList(); if (potentialItems.Count == 0) { return RedirectToAction("Index", new { Controller = "CheckOut", Action = "Index" }); } if(quantity <= potentialItems.Count) { itemDisplayString.Add(quantity + " x " + potentialItems[0].ItemType.ItemName); if (potentialItems[0].ItemType.HasLabel) itemDisplayLabels.Add(potentialItems[0].Label.LabelName); else itemDisplayLabels.Add("(No Label)"); for (int i=0; i<quantity; i++) { var item = db.Items.Find(potentialItems[i].ItemId); if (item == null) return RedirectToAction("Index", new { Controller = "CheckOut", Action = "Index" }); itemsToReturn.Add(item); } } else { TempData["error"] = "Entered quantity is greater than number of items checked out"; return RedirectToAction("Index", new { Controller = "CheckOut", Action = "Index" }); } } index++; } CheckInItemConfirmModel confirmVm = new CheckInItemConfirmModel { ItemDisplayString = itemDisplayString, ItemDisplayLabels = itemDisplayLabels, ItemsToReturn = itemsToReturn, SelectedSchoolId = vm.SelectedSchoolId }; TempData["CheckInItemConfirmModel"] = confirmVm; return RedirectToAction("Confirm"); }
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"); }