public ActionResult Index(CheckInViewModel checkin) { checkin.BranchesViewList = new List <Branch>(branchRepo.GetAllIncludingCheckedOutBranch()); if (!Holding.IsBarcodeValid(checkin.Barcode)) { ModelState.AddModelError(ModelKey, "Invalid holding barcode format."); return(View(checkin)); } var holding = HoldingsControllerUtil.FindByBarcode(holdingRepo, checkin.Barcode); if (holding == null) { ModelState.AddModelError(ModelKey, "Invalid holding barcode."); return(View(checkin)); } if (!holding.IsCheckedOut) { ModelState.AddModelError(ModelKey, "Holding is already checked in."); return(View(checkin)); } holding.CheckIn(TimeService.Now, checkin.BranchId); holdingRepo.Save(holding); return(RedirectToAction("Index")); }
public ActionResult Index(CheckOutViewModel checkout) { if (!ModelState.IsValid) { return(View(checkout)); } checkout.BranchesViewList = new List <Branch>(branchRepo.GetAllIncludingCheckedOutBranch()); var patron = patronRepo.GetByID(checkout.PatronId); if (patron == null) { ModelState.AddModelError(ModelKey, "Invalid patron ID."); return(View(checkout)); } if (!Holding.IsBarcodeValid(checkout.Barcode)) { ModelState.AddModelError(ModelKey, "Invalid holding barcode format."); return(View(checkout)); } var holding = HoldingsControllerUtil.FindByBarcode(holdingRepo, checkout.Barcode); if (holding == null) { ModelState.AddModelError(ModelKey, "Invalid holding barcode."); return(View(checkout)); } if (holding.IsCheckedOut) { ModelState.AddModelError(ModelKey, "Holding is already checked out."); return(View(checkout)); } // TODO determine policy material, which in turn comes from from Isbn lookup on creation // Currently Holding creation in controller does not accept ISBN holding.CheckOut(TimeService.Now, checkout.PatronId, new BookCheckoutPolicy()); holdingRepo.Save(holding); return(RedirectToAction("Index")); }
public void IsValidBarcodeReturnsTrueWhenFormattedCorrectly() { Assert.True(Holding.IsBarcodeValid("ABC:1")); }
public void IsValidBarcodeReturnsFalseWhenItsClassificationIsEmpty() { Assert.False(Holding.IsBarcodeValid(":1")); }
public void IsValidBarcodeReturnsFalseWhenItsCopyNumberNotPositiveInt() { Assert.False(Holding.IsBarcodeValid("ABC:X")); Assert.False(Holding.IsBarcodeValid("ABC:0")); }
public void IsValidBarcodeReturnsFalseWhenItHasNoColon() { Assert.False(Holding.IsBarcodeValid("ABC")); }
public void IsValidBarcodeReturnsFalseWhenItHasNoColon() { Assert.That(Holding.IsBarcodeValid("ABC"), Is.False, "Barcode valid when expected to be false"); }