Exemple #1
0
        public ActionResult ListBook()
        {
            try
            {
                BookTable          bookTable   = new BookTable(db);
                IEnumerable <Book> booksModel  = bookTable.GetBooks();
                string             searchValue = Request.Form[ProjectConstants.SearchValue];

                //IF it is a clear action, empty the search textbox
                if (Request.Form[ProjectConstants.Action] != null && Request.Form[ProjectConstants.Action] == ProjectConstants.Clear)
                {
                    searchValue = null;
                }

                //Check for filter
                if (searchValue != null)
                {
                    ViewBag.SearchValue = searchValue;
                    booksModel          = booksModel.Where(book => book.Name.Contains(searchValue));
                }

                return(View(booksModel));
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemple #2
0
        public void GetBooks()
        {
            Mock <IDatabase>                    mock      = new Mock <IDatabase>();
            BookTable                           booktable = new BookTable(mock.Object);
            Dictionary <string, string>         parameter = new Dictionary <string, string>();
            List <Dictionary <string, string> > result    = new List <Dictionary <string, string> >();

            parameter.Add("Author", "test");
            parameter.Add("Book_id", "9");
            parameter.Add("No_of_books", "10");
            parameter.Add("Name", "test");
            parameter.Add("Rack_No", "11");
            parameter.Add("Status", "test");
            result.Add(parameter);
            mock.Setup(x => x.Query(It.IsAny <string>(), It.IsAny <Dictionary <string, object> >())).Returns(result);
            Book book = new Book();

            Assert.IsInstanceOfType(booktable.GetBooks(), typeof(List <Book>));
        }
Exemple #3
0
        public Boolean ValidateBook(Book newbook)
        {
            try
            {
                BookTable          bookTable   = new BookTable(new MySQLDatabase());
                IEnumerable <Book> ListofBooks = bookTable.GetBooks();
                //  validate and check whether the Book is already existing
                foreach (var book in ListofBooks)
                {
                    if (newbook.Name == book.Name && newbook.Author == book.Author)
                    {
                        return(false);
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }

            try
            {
                // to check whether Status is null or empty
                if (String.IsNullOrEmpty(newbook.Status))
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                throw;
            }

            try
            {
                // to check whether a rack no is greater then zero and not negative

                if (newbook.Rackno <= 0)
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                throw;
            }

            try
            {
                // No of books should atleast be 1
                if (newbook.Count <= 0)
                {
                    return(false);
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(true);
        }