Exemplo n.º 1
0
        public ActionResult SearchBook(int id, string name, string author, string type, string genre)
        {
            using (var db = new LIBRARYEntities())
            {
                var books = new List <Book>();


                var notBorrowed = db.Books.Where(x => x.IsBorrowed == false).ToList();

                foreach (var book in notBorrowed)
                {
                    if (((book.BookName.ToUpper().Contains(name.ToUpper())) || (name == "")) && ((book.BookAuthor.ToUpper().Contains(author.ToUpper())) || (author == "")) && ((book.BookType.ToUpper().Contains(type.ToUpper())) || (type == "")) && ((book.BookGenre.ToUpper().Contains(genre.ToUpper())) || (genre == "")))
                    {
                        books.Add(book);
                    }
                }
                if (books.Count == 0)
                {
                    ViewBag.Message = "There is no book that match";
                    return(View(id));
                }
                else
                {
                    var model = new Models.Readers.SearchedBooks
                    {
                        id           = id,
                        SearchedBook = books
                    };

                    return(View("SearchBookResult", model));
                }
            }
        }
Exemplo n.º 2
0
        public ActionResult DisplayBooks(int id)
        {
            using (var db = new LIBRARYEntities())
            {
                var notBorrowed = new List <Book>();

                foreach (var book in db.Books)
                {
                    if (book.IsBorrowed == false)
                    {
                        notBorrowed.Add(book);
                    }
                }

                if (notBorrowed.Count == 0)
                {
                    ViewBag.Message = "No books to display";
                }

                var account = db.Accounts.Where(x => x.AccountID == id).Single();

                var reader = db.Readers.Where(x => x.ReaderID == account.ReaderID).Single();



                var model = new Models.Readers.SearchedBooks
                {
                    id           = id,
                    SearchedBook = notBorrowed,
                    Count        = reader.NrOfBooks()
                };

                return(View(model));
            }
        }
Exemplo n.º 3
0
        public ActionResult DisplayBooks(int id, int code)
        {
            using (var db = new LIBRARYEntities())
            {
                try {
                    var account = db.Accounts.Where(x => x.AccountID == id).Single();

                    var reader = db.Readers.Where(x => x.ReaderID == account.ReaderID).Single();

                    var book = db.Books.Where(x => x.BookID == code).Single();

                    var bbook = new BorrowedBook
                    {
                        BookID       = book.BookID,
                        ReaderID     = reader.ReaderID,
                        BorrowedDate = DateTime.Now,
                        ExpectDate   = DateTime.Now.AddMonths(1)
                    };

                    book.IsBorrowed = true;
                    db.BorrowedBooks.Add(bbook);

                    db.SaveChanges();

                    var notBorrowed = new List <Book>();

                    foreach (var item in db.Books)
                    {
                        if (item.IsBorrowed == false)
                        {
                            notBorrowed.Add(item);
                        }
                    }

                    if (notBorrowed.Count == 0)
                    {
                        ViewBag.Message = "No books to display";
                    }

                    var model = new Models.Readers.SearchedBooks
                    {
                        id           = id,
                        SearchedBook = notBorrowed,
                        Count        = reader.NrOfBooks()
                    };
                    return(View(model));
                }
                catch (Exception)
                {
                    ViewBag.Message = "No account with the give id";
                    return(View("Login"));
                }
            }
        }