Пример #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));
                }
            }
        }
Пример #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));
            }
        }
Пример #3
0
        public ActionResult BorrowedBooks(int id)
        {
            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 books = db.BorrowedBooks.Where(x => x.ReturnDate == null).Where(x => x.ReaderID == reader.ReaderID)
                                .Join(db.Books,
                                      bbook => bbook.BookID,
                                      book => book.BookID,
                                      (bbook, book) => new { BBook = bbook, Book = book }
                                      ).Select(y => new { y.Book.BookID, y.Book.BookName, y.BBook.ExpectDate })
                                .ToList().OrderBy(x => x.BookID)
                                .Select(x => new Models.Readers.BBook {
                        ID = x.BookID, Name = x.BookName, ExpectDate = x.ExpectDate
                    }).ToList();
                    var model = new Models.Readers.BBooks
                    {
                        Id    = id,
                        books = books
                    };

                    return(View(model));
                }
                catch (Exception)
                {
                    ViewBag.Message = "No account with the given id";
                    return(View("Login"));
                }
            }
        }
Пример #4
0
        public ActionResult ChangePass(int id, string current, string newPass)
        {
            using (var db = new LIBRARYEntities())
            {
                try
                {
                    var account = db.Accounts.Where(x => x.AccountID == id).Single();

                    if (current != account.AccountPassword)
                    {
                        ViewBag.Message = "Wrong password";
                        return(View(id));
                    }
                    if (newPass == current)
                    {
                        ViewBag.Message = "New password can't be the old password";
                        return(View(id));
                    }

                    account.AccountPassword = newPass;

                    db.SaveChanges();

                    return(View(id));
                }
                catch (Exception)
                {
                    ViewBag.Message = "No account with the given id";
                    return(View("Login"));
                }
            }
        }
Пример #5
0
 public ActionResult DisplayReaders()
 {
     using (var db = new LIBRARYEntities())
     {
         if (db.Readers.Count() == 0)
         {
             ViewBag.Message = "No readers to display";
         }
         return(View(db.Readers.ToList()));
     }
 }
Пример #6
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"));
                }
            }
        }
Пример #7
0
        public ActionResult ReturnBook(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();

                    if (reader.NrOfBooks() == 0)
                    {
                        ViewBag.Message = "No book to return";
                        return(View(id));
                    }

                    if (code <= 0)
                    {
                        ViewBag.Message = "Invalid input";
                        return(View(id));
                    }

                    try
                    {
                        var bbook = db.BorrowedBooks.Where(x => x.ReaderID == reader.ReaderID && x.ReturnDate == null && x.BookID == code).Single();

                        bbook.ReturnDate = DateTime.Now;

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

                        book.IsBorrowed = false;

                        db.SaveChanges();

                        return(View(id));
                    }
                    catch (Exception)
                    {
                        ViewBag.Message = "No book with the given code";
                        return(View(id));
                    }
                }
                catch (Exception)
                {
                    ViewBag.Message = "No account with the given id";
                    return(View("Login"));
                }
            }
        }
Пример #8
0
        public ActionResult HistoryOfTheReader(int id)
        {
            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 history = db.BorrowedBooks.Where(x => x.ReaderID == reader.ReaderID)
                                  .Join(db.Books,
                                        bbook => bbook.BookID,
                                        book => book.BookID,
                                        (bbook, book) => new { BBook = bbook, Book = book })
                                  .Select(y => new { y.BBook.BorrowedDate, y.BBook.ExpectDate, y.BBook.ReturnDate, y.Book.BookName })
                                  .OrderBy(x => x.BorrowedDate).ToList()
                                  .Select(x => new Models.ReaderHistory {
                        ReaderName = reader.ReaderName, BookName = x.BookName, BorrowedDate = x.BorrowedDate, ExpectDate = x.ExpectDate, ReturnDate = x.ReturnDate
                    }).ToList();
                    if (history.Count == 0)
                    {
                        ViewBag.Message = "The reader never borrowed a book";
                        return(View(id));
                    }

                    var model = new Models.Readers.ReaderModel
                    {
                        Id   = id,
                        list = history
                    };
                    return(View(model));
                }
                catch (Exception)
                {
                    ViewBag.Message = "No account with the given id";
                    return(View("Login"));
                }
            }
        }
Пример #9
0
 public ActionResult SearchBook(string name, string author, string type, string genre)
 {
     ViewBag.Message = string.Empty;
     using (var db = new LIBRARYEntities())
     {
         var books = new List <Book>();
         foreach (var book in db.Books)
         {
             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());
         }
         else
         {
             return(View("SearchBookResult", books));
         }
     }
 }
Пример #10
0
        public ActionResult BorrowBook(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();

                    if (reader.NrOfBooks() >= 4)
                    {
                        ViewBag.Message = "Can't borrow more books";
                        return(View(id));
                    }

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

                    if (books.Count == 0)
                    {
                        ViewBag.Message = "No books to borrow";
                        return(View(id));
                    }

                    if (code <= 0)
                    {
                        ViewBag.Message = "Invalid input";
                        return(View(id));
                    }
                    try
                    {
                        var book = 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();

                        return(View(id));
                    }
                    catch (Exception)
                    {
                        ViewBag.Message = "No book with the given code";
                        return(View(id));
                    }
                }
                catch (Exception)
                {
                    ViewBag.Message = "No account with the given id";
                    return(View("Login"));
                }
            }
        }
Пример #11
0
 public Delivarybookss()
 {
     InitializeComponent();
     Dblib = new LIBRARYEntities();
 }
Пример #12
0
 public BooksOnClient()
 {
     InitializeComponent();
     DBlib = new LIBRARYEntities();
 }
Пример #13
0
 public LibraryBooks()
 {
     InitializeComponent();
     Dblib = new LIBRARYEntities();
 }