//Check All Items being returned public ActionResult CheckInItems(CheckInItemConfirmModel vm) { if (Session["isAdmin"] == null) return RedirectToAction("Index", new { controller = "Home", action = "Index" }); if (vm == null || Session["LoggedUserId"]==null) return RedirectToAction("Index", new { Controller = "CheckOut", Action = "Index" }); string userName = (string)Session["LoggedUserID"]; for(int i=0; i< vm.ItemsToReturn.Count; i++) { var item = db.Items.Find(vm.ItemsToReturn[i].ItemId); if (item == null) return RedirectToAction("Index", new { Controller = "CheckOut", Action = "Index" }); if (item.CheckedInById != null) return RedirectToAction("Index", new { Controller = "CheckOut", Action = "Index" }); item.CheckedInById = userName; db.Entry(item).State = EntityState.Modified; db.SaveChanges(); } //TempData["CheckInViewModel"] = vm; //return RedirectToAction("InventoryReturnReminder"); return RedirectToAction("Index", new { Controller = "CheckOut", Action = "Index" }); }
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"); }