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 void NextAvailableCopyNumberIncrementsCopyNumberUsingCount() { holdingRepo.Create(new Holding("AB123:1")); holdingRepo.Create(new Holding("AB123:2")); holdingRepo.Create(new Holding("XX123:1")); var copyNumber = HoldingsControllerUtil.NextAvailableCopyNumber(holdingRepo, "AB123"); Assert.That(copyNumber, Is.EqualTo(3)); }
public void FindByBarcodeReturnsHoldingMatchingClassificationAndCopy() { var holding = new Holding { Classification = "AA123", CopyNumber = 2 }; repo.Create(holding); Assert.That(HoldingsControllerUtil.FindByBarcode(repo, "AA123:2"), Is.EqualTo(holding)); }
public void CreateAssignsCopyNumberWhenNotProvided() { controller.Create(new Holding() { Classification = "AB123", CopyNumber = 0 }); var holding = HoldingsControllerUtil.FindByBarcode(holdingRepo, "AB123:1"); Assert.That(holding.Barcode, Is.EqualTo("AB123:1")); }
public void CreatePersistsHolding() { controller.Create(new Holding() { Classification = "AB123", CopyNumber = 1 }); var holding = HoldingsControllerUtil.FindByBarcode(holdingRepo, "AB123:1"); Assert.That(holding.Barcode, Is.EqualTo("AB123:1")); }
public Holding AddNewMaterial(string isbn) { var classification = classificationService.Classification(isbn); var holding = new Holding { Classification = classification, CopyNumber = HoldingsControllerUtil.NextAvailableCopyNumber(holdingRepo, classification), BranchId = BranchId }; holdingRepo.Create(holding); return(holding); }
public void CreateUsesHighwaterOnlyForBooksWithSameClassification() { controller.Create(new Holding() { Classification = "AB123", CopyNumber = 1, HeldByPatronId = 1 }); controller.Create(new Holding() { Classification = "XX999", CopyNumber = 0, HeldByPatronId = 2 }); var holding = HoldingsControllerUtil.FindByBarcode(holdingRepo, "XX999:1"); Assert.That(holding.HeldByPatronId, Is.EqualTo(2)); }
public void CreateUsesHighwaterCopyNumberWhenAssigning() { controller.Create(new Holding() { Classification = "AB123", CopyNumber = 1, HeldByPatronId = 1 }); controller.Create(new Holding() { Classification = "AB123", CopyNumber = 0, HeldByPatronId = 2 }); var holding = HoldingsControllerUtil.FindByBarcode(holdingRepo, "AB123:2"); Assert.That(holding.HeldByPatronId, Is.EqualTo(2)); }
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 ActionResult Create([Bind(Include = "Id,Classification,CopyNumber,CheckOutTimestamp,BranchId,HeldByPatronId,LastCheckedIn")] Holding holding) { if (ModelState.IsValid) { if (holding.CopyNumber == 0) { holding.CopyNumber = HoldingsControllerUtil.NextAvailableCopyNumber(holdingRepo, holding.Classification); } else { if (HoldingsControllerUtil.FindByBarcode(holdingRepo, holding.Barcode) != null) { ModelState.AddModelError(ModelKey, "Duplicate classification / copy number combination."); return(View(holding)); } } var id = holdingRepo.Create(holding); return(RedirectToAction("Index", new { ID = id })); } return(View(holding)); }
public void FindByBarcodeReturnsNullWhenNotFound() { Assert.That(HoldingsControllerUtil.FindByBarcode(repo, "AA:1"), Is.Null); }
public void ByClassificationAndCopyReturnsMatchingHolding() { Assert.That(HoldingsControllerUtil.FindByClassificationAndCopy(holdingRepo, "XX123", 1).Id, Is.EqualTo(idForXX123_1)); }
public void ByBarcodeReturnsMatchingHolding() { Assert.That(HoldingsControllerUtil.FindByBarcode(holdingRepo, "AB123:2").Id, Is.EqualTo(idForAB123_2)); }
// 1/19/2017: who wrote this? // // FIXME. Fix this mess. We just have to SHIP IT for nwo!!! public void AcceptBarcode(string bc) { var cl = Holding.ClassificationFromBarcode(bc); var cn = Holding.CopyNumberFromBarcode(bc); var h = HoldingsControllerUtil.FindByBarcode(holdingRepo, bc); if (h.IsCheckedOut) { if (cur == NoPatron) { // ci bc = h.Barcode; var patronId = h.HeldByPatronId; var cis = TimeService.Now; Material m = null; m = classificationService.Retrieve(h.Classification); var fine = m.CheckoutPolicy.FineAmount(h.CheckOutTimestamp.Value, cis); var p = patronRepo.GetByID(patronId); p.Fine(fine); patronRepo.Save(p); h.CheckIn(cis, brId); holdingRepo.Save(h); } else { if (h.HeldByPatronId != cur) // check out book already cked-out { var bc1 = h.Barcode; var n = TimeService.Now; var t = TimeService.Now.AddDays(21); var f = classificationService.Retrieve(h.Classification).CheckoutPolicy.FineAmount(h.CheckOutTimestamp.Value, n); var patron = patronRepo.GetByID(h.HeldByPatronId); patron.Fine(f); patronRepo.Save(patron); h.CheckIn(n, brId); holdingRepo.Save(h); // co h.CheckOut(n, cur, CheckoutPolicies.BookCheckoutPolicy); holdingRepo.Save(h); // call check out controller(cur, bc1); t.AddDays(1); n = t; } else // not checking out book already cked out by other patron { // otherwise ignore, already checked out by this patron } } } else { if (cur != NoPatron) // check in book { h.CheckOut(cts, cur, CheckoutPolicies.BookCheckoutPolicy); holdingRepo.Save(h); } else { throw new CheckoutException(); } } }
Holding GetByBarcode(string barcode) { return(HoldingsControllerUtil.FindByBarcode(holdingRepo, barcode)); }