Beispiel #1
0
        public BookTranscation GetBookTransactionById(string transasctionId)
        {
            try
            {
                string commandText = ProjectConstants.BTGetBookById;
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add(ProjectConstants.transactionId, transasctionId);

                var book = database.Query(commandText, parameters).FirstOrDefault();
                if (book == null)
                {
                    return(null);
                }

                BookTranscation currentBook = new BookTranscation();
                currentBook.TranscationID = Convert.ToInt32(book[ProjectConstants.KeyTransactionID]);
                currentBook.BookID        = Convert.ToInt32(book["Book_ID"]);
                currentBook.BookStatus    = book["BookStatus"];
                currentBook.MemberID      = Convert.ToInt32(book["Member_ID"]);
                currentBook.DueDate       = DateTime.Parse(book["Due_Date"]);
                currentBook.DateofIssue   = DateTime.Parse(book["Date_of_issue"]);

                return(currentBook);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #2
0
        public ActionResult ReturnTransaction(string id)
        {
            string bookId = string.Empty;

            try
            {
                BookTranscationTable bookTransactionTable = new BookTranscationTable(db);


                BookTranscation currentTransaction = bookTransactionTable.GetBookTransactionById(id);

                if (currentTransaction != null)
                {
                    currentTransaction.BookStatus = BookTransactionStatus.Returned.ToString();
                    bookTransactionTable.RenewBook(currentTransaction);
                    bookId = Convert.ToString(currentTransaction.BookID);
                }
                else
                {
                    return(RedirectToAction(ProjectConstants.ListBookTranscation));
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(RedirectToAction(ProjectConstants.ReturnBook, new { @id = bookId }));
        }
Beispiel #3
0
        public void Valid_ReturnTranscation()
        {
            Mock <IDatabase>                    mock            = new Mock <IDatabase>();
            BookController                      bookcontroller  = new BookController(mock.Object);
            Dictionary <string, string>         parameter       = new Dictionary <string, string>();
            List <Dictionary <string, string> > result          = new List <Dictionary <string, string> >();
            BookTranscation                     booktranscation = new BookTranscation();

            booktranscation.SetTranscationID(0);
            booktranscation.SetMemberID(0);
            booktranscation.SetBookID(0);
            booktranscation.SetBookStatus("available");
            booktranscation.SetDateofissue(new DateTime(2018, 07, 22));
            booktranscation.SetDueDate(new DateTime(2018, 07, 22));
            mock.Setup(x => x.Query(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(result);
            parameter.Add("Transcation_ID", "11");
            parameter.Add("Member_ID", "25");
            parameter.Add("Book_ID", "123");
            parameter.Add("BookStatus", "Available");
            parameter.Add("Due_Date", "2018, 07, 22");
            parameter.Add("Date_of_issue", "2018, 07, 22");
            result.Add(parameter);
            var bookreturntranscation = bookcontroller.RenewTransaction("4081") as RedirectToRouteResult;

            Assert.IsNotNull(bookreturntranscation);
        }
        public void GetBooksIssued_Eception()
        {
            Mock <IDatabase>                    mock           = new Mock <IDatabase>();
            Mock <DashboardTable>               mockdash       = new Mock <DashboardTable>();
            DashboardTable                      dashboardtable = new DashboardTable(mock.Object);
            Dictionary <string, string>         parameter      = new Dictionary <string, string>();
            List <Dictionary <string, string> > result         = new List <Dictionary <string, string> >();

            parameter.Add("Blank", "10");
            parameter.Add("Book_ID", "9");
            parameter.Add("BookStatus", "Renewed");
            parameter.Add("Member_ID", "25");
            parameter.Add("Due_Date", "2018-07-22 17:35:23");
            parameter.Add("Date_of_issue", "2018-07-22 17:35:23");
            result.Add(parameter);
            BookTranscation book = new BookTranscation();

            book.SetMemberID(1);
            book.SetBookID(2);
            book.SetBookStatus("Issued");
            book.SetDateofissue(DateTime.Now);
            book.SetDueDate(DateTime.Now);
            mock.Setup(x => x.Query(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(result);
            //mockdash.Setup(x => x.GetActiveBookTranscation()).Returns(book);
            Assert.IsInstanceOfType(dashboardtable.GetBooksIssued(), typeof(IEnumerable <BookTranscation>));
        }
Beispiel #5
0
        public ActionResult RenewTransaction(string id)
        {
            string bookId = string.Empty;

            try
            {
                BookTranscationTable bookTransactionTable = new BookTranscationTable(db);


                BookTranscation currentTransaction = bookTransactionTable.GetBookTransactionById(id);

                if (currentTransaction != null)
                {
                    currentTransaction.DueDate    = currentTransaction.DueDate.AddDays(Convert.ToDouble(WebConfigurationManager.AppSettings[ProjectConstants.BookDueDateDays]));
                    currentTransaction.BookStatus = BookTransactionStatus.Renewed.ToString();
                    bookTransactionTable.RenewBook(currentTransaction);
                    bookId = Convert.ToString(currentTransaction.BookID);
                }
                else
                {
                    return(RedirectToAction(ProjectConstants.ListBookTranscation));
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(RedirectToAction(ProjectConstants.RenewBook, new { @id = bookId }));
        }
Beispiel #6
0
        public IEnumerable <BookTranscation> GetActiveBookTranscation()
        {
            try
            {
                string commandText = ProjectConstants.DashboardGetActiveBookTransaction + BookTransactionStatus.Returned + "'";

                List <Dictionary <string, string> > books = database.Query(commandText, null);
                List <BookTranscation> result             = new List <BookTranscation>();
                foreach (var book in books)
                {
                    BookTranscation currentBook = new BookTranscation();
                    currentBook.TranscationID = Convert.ToInt32(book["Transcation_ID"]);
                    currentBook.BookID        = Convert.ToInt32(book["Book_ID"]);
                    currentBook.BookStatus    = book["BookStatus"];
                    currentBook.MemberID      = Convert.ToInt32(book["Member_ID"]);
                    currentBook.DueDate       = DateTime.Parse(book["Due_Date"]);
                    currentBook.DateofIssue   = DateTime.Parse(book["Date_of_issue"]);
                    result.Add(currentBook);
                }

                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #7
0
 public ActionResult IssueBook(BookTranscation booktranscation)
 {
     if (ModelState.IsValid)
     {
         BookTranscationTable bookTranscation = new BookTranscationTable(db);
         bookTranscation.Insert(booktranscation);
     }
     return(View(ProjectConstants.IssueBook));
 }
Beispiel #8
0
        public int RenewBook(BookTranscation booktranscation)
        {
            string commandText = ProjectConstants.BTRenewBook;
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add("@duedate", booktranscation.DueDate);
            parameters.Add("@BookStatus", booktranscation.BookStatus);
            parameters.Add("@transcationid", booktranscation.TranscationID);



            return(database.Execute(commandText, parameters));
        }
Beispiel #9
0
        public void IssueBook_inValidCount()
        {
            Mock <IDatabase> mock = new Mock <IDatabase>();

            mock.Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(1);
            BookController bookcontroller = new BookController(mock.Object);
            var            book           = new BookTranscation {
                TranscationID = 100, MemberID = 25, BookID = 22, BookStatus = "available", DateofIssue = new DateTime(2018, 07, 12), DueDate = new DateTime(2018, 07, 22)
            };
            var result = bookcontroller.IssueBook(book) as ViewResult;

            Assert.AreEqual("IssueBook", result.ViewName);
        }
        public void GetCountBooksIssued_Null()
        {
            Mock <IDatabase> mock = new Mock <IDatabase>();

            mock.Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(1);
            DashboardTable booktable = new DashboardTable(mock.Object);
            Dictionary <string, string>         parameter = new Dictionary <string, string>();
            List <Dictionary <string, string> > result    = new List <Dictionary <string, string> >();
            BookTranscation book = new BookTranscation();

            mock.Setup(x => x.Query(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(result);
            Assert.AreEqual(0, booktable.GetCountBooksIssued());
        }
Beispiel #11
0
        public void IssueBook_InvalidMemberID()
        {
            Mock <IDatabase> mock = new Mock <IDatabase>();

            mock.Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(1);
            BookController bookcontroller = new BookController(mock.Object);
            var            book           = new BookTranscation {
                TranscationID = 100, MemberID = 01, BookID = 4080, BookStatus = "available", DateofIssue = new DateTime(2018, 07, 12), DueDate = new DateTime(2018, 07, 22)
            };
            var result = bookcontroller.IssueBook(book) as ViewResult;

            Assert.IsNotNull(result);
        }
Beispiel #12
0
        public int Insert(BookTranscation booktranscation)
        {
            string commandText = ProjectConstants.BTInsert;
            Dictionary <string, object> parameters = new Dictionary <string, object>();

            parameters.Add(ProjectConstants.TransactionID, booktranscation.TranscationID);
            parameters.Add(ProjectConstants.MemberID, booktranscation.MemberID);
            parameters.Add(ProjectConstants.BookID, booktranscation.BookID);
            parameters.Add(ProjectConstants.DateOfIssue, booktranscation.DateofIssue);
            parameters.Add(ProjectConstants.DueDate, booktranscation.DueDate);
            parameters.Add(ProjectConstants.TransactionBookStatus, booktranscation.BookStatus);

            return(database.Execute(commandText, parameters));
        }
        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);
        }
Beispiel #14
0
        public void IssueBook_invalidBookID()
        {
            Mock <IDatabase> mock = new Mock <IDatabase>();

            mock.Setup(x => x.Execute(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(1);
            BookController bookcontroller = new BookController(mock.Object);
            var            book           = new BookTranscation();

            book.SetTranscationID(11);
            book.SetMemberID(25);
            book.SetBookID(3);
            book.SetBookStatus("available");
            book.SetDateofissue(new DateTime(2018, 07, 22));
            book.SetDueDate(new DateTime(2018, 07, 22));
            var result = bookcontroller.IssueBook(book) as ViewResult;

            Assert.IsNotNull(result);
        }
Beispiel #15
0
        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));
        }
Beispiel #16
0
        public async Task <IActionResult> BookReturn([FromBody] BookTranscation bookTranscation)
        {
            try
            {
                var result = await _bookTranscationService.BookReturn(bookTranscation);

                return(Ok(result));
            }
            catch (ArgumentNullException argNullEx)
            {
                return(BadRequest(argNullEx.Message));
            }
            catch (ArgumentException argEx)
            {
                return(BadRequest(argEx.Message));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }
Beispiel #17
0
        public IEnumerable <BookTranscation> GetBookTransactionsByBookId(int bookId, bool onlyIssuedAndRenewed = true)
        {
            try
            {
                string commandText = ProjectConstants.BTGetBookByBookId;
                if (onlyIssuedAndRenewed)
                {
                    commandText += " and BookStatus != '" + BookTransactionStatus.Returned + "'";
                }
                Dictionary <string, object> parameters = new Dictionary <string, object>();
                parameters.Add("@bookId", bookId);

                var transasction = database.Query(commandText, parameters);
                if (transasction == null)
                {
                    return(null);
                }
                List <BookTranscation> result = new List <BookTranscation>();
                foreach (var book in transasction)
                {
                    BookTranscation currentBook = new BookTranscation();
                    currentBook.TranscationID = Convert.ToInt32(book["Transcation_ID"]);
                    currentBook.BookID        = Convert.ToInt32(book["Book_ID"]);
                    currentBook.BookStatus    = book["BookStatus"];
                    currentBook.MemberID      = Convert.ToInt32(book["Member_ID"]);
                    currentBook.DueDate       = DateTime.Parse(book["Due_Date"]);
                    currentBook.DateofIssue   = DateTime.Parse(book["Date_of_issue"]);
                    result.Add(currentBook);
                }

                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
Beispiel #18
0
 public int Delete(BookTranscation booktranscation)
 {
     return(DeleteByTranscationId(booktranscation.TranscationID.ToString()));
 }