public ActionResult IssueBook(BookTranscation booktranscation) { if (ModelState.IsValid) { BookTranscationTable bookTranscation = new BookTranscationTable(db); bookTranscation.Insert(booktranscation); } return(View(ProjectConstants.IssueBook)); }
public void RenewBook() { Mock <IDatabase> mock = new Mock <IDatabase>(); mock.Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(1); BookTranscationTable booktable = new BookTranscationTable(mock.Object); BookTranscation book = new BookTranscation(); book.SetTranscationID(1); book.SetBookStatus("Renewed"); book.SetDueDate(DateTime.Now); int result = booktable.Insert(book); Assert.AreEqual(1, result); }
public ActionResult Issue(BookTransactionViewModel transactionViewModel) { try { if (transactionViewModel == null) { throw new ArgumentException(ProjectConstants.InvalidTransactionMsg); } MemberTable memberTable = new MemberTable(db); LibMember member = memberTable.GetMemberById(Convert.ToString(transactionViewModel.MemberID)); if (member == null) { ModelState.AddModelError(string.Empty, ProjectConstants.MemberIdNotExistMsg); return(View(transactionViewModel)); } BookTable bookTable = new BookTable(db); Book book = bookTable.GetBookById(Convert.ToString(transactionViewModel.BookID)); BookTranscationTable bookTranscationTable = new BookTranscationTable(db); BookTranscation bookTranscation = new BookTranscation() { BookID = transactionViewModel.BookID, BookStatus = transactionViewModel.BookStatus, MemberID = transactionViewModel.MemberID, DateofIssue = transactionViewModel.DateofIssue, DueDate = transactionViewModel.DueDate }; bookTranscationTable.Insert(bookTranscation); int existingBookTransactionCount = bookTranscationTable.GetBookTransactionCountByBookId(bookTranscation.BookID); if (existingBookTransactionCount >= book.Count) { // update the book status as Not Available book.Status = BookStatus.NotAvailable.ToString(); bookTable.Update(book); } } catch (Exception) { throw; } return(RedirectToAction(ProjectConstants.ListBookTranscation)); }