Пример #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 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));
        }