Example #1
0
 public ActionResult Create(string bookTitle, string bookAuthor)
 {
     if (BookClass.CheckBookExistByTitle(bookTitle) == false && AuthorClass.CheckAuthorExistByName(bookAuthor) == false)
     {
         BookClass.Save(bookTitle);
         AuthorClass.Save(bookAuthor);
         int bookId   = BookClass.GetBookByTitle(bookTitle).GetId();
         int authorId = (AuthorClass.GetAuthorByName(bookAuthor)).GetId();
         JoinBookAuthorClass.Save(authorId, bookId);
         int initial = 1;
         CopiesClass.Save(bookId, initial, initial);
         return(RedirectToAction("New"));
     }
     else if (BookClass.CheckBookExistByTitle(bookTitle) == true && AuthorClass.CheckAuthorExistByName(bookAuthor) == true)
     {
         int bookId      = BookClass.GetBookByTitle(bookTitle).GetId();
         int amount      = CopiesClass.GetAmountByBookId(bookId);
         int totalAmount = CopiesClass.GetTotalByBookId(bookId);
         totalAmount++;
         amount++;
         CopiesClass.Update(bookId, amount);
         CopiesClass.UpdateTotal(bookId, totalAmount);
         return(RedirectToAction("New"));
     }
     else
     {
         BookClass.Save(bookTitle);
         int bookId   = BookClass.GetBookByTitle(bookTitle).GetId();
         int authorId = (AuthorClass.GetAuthorByName(bookAuthor)).GetId();
         JoinBookAuthorClass.Save(authorId, bookId);
         int initial = 1;
         CopiesClass.Save(bookId, initial, initial);
         return(RedirectToAction("New"));
     }
 }
Example #2
0
        public ActionResult Create(string patronName, string bookTitle)
        {
            int check = 1;

            if (BookClass.CheckBookExistByTitle(bookTitle) == false)
            {
                check = 0;
            }
            else
            {
                if (PatronClass.CheckPatronExistByName(patronName) == false)
                {
                    PatronClass.Save(patronName);
                    int bookId   = BookClass.GetBookByTitle(bookTitle).GetId();
                    int patronId = PatronClass.GetPatronIdByName(patronName);
                    JoinPatronBookClass.SavePatronCopy(patronId, bookId);
                    int amount = CopiesClass.GetAmountByBookId(bookId);
                    amount--;
                    CopiesClass.Update(bookId, amount);
                }
                else
                {
                    int bookId   = BookClass.GetBookByTitle(bookTitle).GetId();
                    int patronId = PatronClass.GetPatronIdByName(patronName);
                    JoinPatronBookClass.SavePatronCopy(patronId, bookId);
                    int amount = CopiesClass.GetAmountByBookId(bookId);
                    amount--;
                    CopiesClass.Update(bookId, amount);
                }
            }
            return(View("New", check));
        }
Example #3
0
        public ActionResult SearchBook(string bookTitleSearch)
        {
            BookClass book = BookClass.GetBookByTitle(bookTitleSearch);
            int       id   = book.GetId();
            Dictionary <string, object> dictionary = new Dictionary <string, object> {
            };
            BookClass   newBook   = BookClass.GetBookById(id);
            AuthorClass newAuthor = AuthorClass.GetAuthorByBookId(id);
            int         amount    = CopiesClass.GetAmountByBookId(id);
            int         total     = CopiesClass.GetTotalByBookId(id);
            CopiesClass copies    = new CopiesClass(id, amount, total);

            dictionary.Add("book", newBook);
            dictionary.Add("author", newAuthor);
            dictionary.Add("copies", copies);
            return(View("ShowBook", dictionary));
        }