コード例 #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"));
     }
 }
コード例 #2
0
        public ActionResult SearchAuthor(string authorNameSearch)
        {
            AuthorClass author = AuthorClass.GetAuthorByName(authorNameSearch);
            int         id     = author.GetId();
            Dictionary <string, object> dictionary = new Dictionary <string, object> {
            };
            List <BookClass> books = BookClass.GetBooksByAuthorId(id);

            dictionary.Add("books", books);
            dictionary.Add("author", author);
            return(View("ShowAuthor", dictionary));
        }