Exemplo n.º 1
0
        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"));
        }
Exemplo n.º 3
0
 public void IsValidBarcodeReturnsTrueWhenFormattedCorrectly()
 {
     Assert.True(Holding.IsBarcodeValid("ABC:1"));
 }
Exemplo n.º 4
0
 public void IsValidBarcodeReturnsFalseWhenItsClassificationIsEmpty()
 {
     Assert.False(Holding.IsBarcodeValid(":1"));
 }
Exemplo n.º 5
0
 public void IsValidBarcodeReturnsFalseWhenItsCopyNumberNotPositiveInt()
 {
     Assert.False(Holding.IsBarcodeValid("ABC:X"));
     Assert.False(Holding.IsBarcodeValid("ABC:0"));
 }
Exemplo n.º 6
0
 public void IsValidBarcodeReturnsFalseWhenItHasNoColon()
 {
     Assert.False(Holding.IsBarcodeValid("ABC"));
 }
Exemplo n.º 7
0
 public void IsValidBarcodeReturnsFalseWhenItHasNoColon()
 {
     Assert.That(Holding.IsBarcodeValid("ABC"), Is.False, "Barcode valid when expected to be false");
 }