public ActionResult CancelRequest(RequestEntry entry)
        {
            if (ModelState.IsValid)
            {
                    Book bookToCheck = libRepo.BookRepo.Find(entry.BookID);
                    if (bookToCheck == null)
                    {
                        TempData["ErrorNoti"] = "Something went wrong.";
                        return RedirectToAction("Index");
                    }
                    RequestEntry entryToCancel = libRepo.RequestEntryRepo.Find(entry.BookID);
                    if (entryToCancel == null)
                    {
                        TempData["ErrorNoti"] = "This request book is already cancelled.";
                        return RedirectToAction("Index");
                    }
                    else if (entryToCancel.GetRequestUser(ref libRepo).UserName != Session["LoginUser"].ToString().Substring(2))
                    {
                        TempData["ErrorNoti"] = "Something went wrong.";
                        return RedirectToAction("Index");
                    }

                    if (bookToCheck.BookStatus == Status.Reserved)
                    {
                            bookToCheck.BookStatus = Status.Available;
                            libRepo.BookRepo.Update(bookToCheck);
                    }
                    libRepo.RequestEntryRepo.Remove(entryToCancel);
                    libRepo.Save();
                    TempData["SuccessNoti"] = "Cancel request successfully.";
                    return RedirectToAction("Index");
            }
            TempData["ErrorNoti"] = "Something went wrong,please try again.";
            return RedirectToAction("Index");
        }
        public ActionResult Request(RequestEntry entry)
        {
            if (ModelState.IsValid)
            {
                //Check that whether desired book is exists in database.
                Book booktorequest;
                if ((booktorequest = libRepo.BookRepo.Find(entry.BookID)) == null)
                {
                    TempData["ErrorNoti"] = "No book with prefer ID exists.";
                    return View();
                }
                //Check status of book that is that book is borrowed.
                if (booktorequest.BookStatus != Status.Borrowed && booktorequest.BookStatus != Status.Reserved)
                {
                    TempData["ErrorNoti"] = "Can't request this book due to it is "
                        + booktorequest.BookStatus.ToString() + ".";
                    return View();
                }

                //Check that desired book is already requested or not.
                if (booktorequest.GetRelatedRequestEntry(ref libRepo) != null)
                {
                    TempData["ErrorNoti"] = "This book is already requested.";
                    return View();
                }

                /* Check that current request user is same as current borrower's desired book
                 * if this check is not add request entry to mark that desired is requested.
                 */
                Member request_member = libRepo.MemberRepo.ListWhere(target => target.UserName ==
                                                HttpContext.User.Identity.Name.ToString().Substring(2)).Single();
                if (booktorequest.GetRelatedBorrowEntry(ref libRepo).
                    LastOrDefault(target => target.BookID == entry.BookID).GetBorrower(ref libRepo)
                    .UserName == request_member.UserName)
                {
                    TempData["ErrorNoti"] = "Can't request your current borrowed book.";
                    return View();
                }

                entry.UserID = request_member.UserID;
                entry.RequestDate = DateTime.Now;
                libRepo.RequestEntryRepo.Add(entry);
                libRepo.Save();
                TempData["SuccessNoti"] = "Request book successfully.";
                return RedirectToAction("Index");
            }
            else
            {
                TempData["ErrorNoti"] = "Input was not in correct format.";
                return View();
            }
        }
 public void TestRequestPostAction6()
 {
     InitialController("M_paratab", libRepo.Object);
     RequestEntry postReq = new RequestEntry { BookID = 4 };
     ViewResult result = controller.Request(postReq) as ViewResult;
     Assert.AreEqual("Can't request this book due to it is Available.",
         result.TempData["ErrorNoti"]);
     Assert.IsNull(controller.ControllerContext.Controller.
         TempData["SuccessNoti"]);
 }
 public void TestRequestPostAction4()
 {
     InitialController("M_fonniz", libRepo.Object);
     RequestEntry postReq = new RequestEntry { BookID = 2 };
     ViewResult result = controller.Request(postReq) as ViewResult;
     Assert.AreEqual("This book is already requested.", result.TempData["ErrorNoti"]);
     Assert.IsNull(controller.ControllerContext.Controller.TempData["SuccessNoti"]);
 }
 public void TestRequestPostAction3()
 {
     InitialController("M_ce51benz", libRepo.Object);
     RequestEntry postReq = new RequestEntry { BookID = 3 };
     ViewResult result = controller.Request(postReq) as ViewResult;
     Assert.AreEqual("Can't request your current borrowed book.", result.TempData["ErrorNoti"]);
     Assert.IsNull(controller.ControllerContext.Controller.TempData["SuccessNoti"]);
 }
 public void TestRequestPostAction2()
 {
     InitialController("M_baybaybay", libRepo.Object);
     RequestEntry postReq = new RequestEntry { BookID = 100 };
     ViewResult result = controller.Request(postReq) as ViewResult;
     Assert.AreEqual("No book with prefer ID exists.", result.TempData["ErrorNoti"]);
     Assert.IsNull(controller.ControllerContext.Controller.TempData["SuccessNoti"]);
 }
 public void TestRequestPostAction1()
 {
     InitialController("M_baybaybay", libRepo.Object);
     RequestEntry postReq = new RequestEntry { BookID = 3 };
     RedirectToRouteResult result = controller.Request(postReq) as RedirectToRouteResult;
     Assert.AreEqual("Index", result.RouteValues["action"]);
     Assert.AreEqual("Request book successfully.", controller.
         ControllerContext.Controller.TempData["SuccessNoti"]);
     Assert.IsNull(controller.ControllerContext.Controller.TempData["ErrorNoti"]);
 }