Beispiel #1
0
        public ActionResult BuyBook(AuthorBuyBook authorBuyBook)
        {
            Link link = db.Links.FirstOrDefault(z => z.BookId == authorBuyBook.BookId && z.AuthorId == authorBuyBook.AuthorId);

            link.InStock = link.InStock - authorBuyBook.UnitsBuy;
            db.SaveChanges();
            return(Redirect("/Authors"));
        }
Beispiel #2
0
        public ActionResult BuyBook(string AuthorId, string BookId)
        {
            int           authorId      = Int32.Parse(AuthorId);
            int           bookId        = Int32.Parse(BookId);
            AuthorBuyBook authorBuyBook = new AuthorBuyBook();

            authorBuyBook.Author = db.Authors.FirstOrDefault(z => z.Id == authorId);
            Book book = db.Books.FirstOrDefault(z => z.Id == bookId);

            authorBuyBook.bookExtended             = new BookExtended();
            authorBuyBook.bookExtended.Id          = book.Id;
            authorBuyBook.bookExtended.Name        = book.Name;
            authorBuyBook.bookExtended.ImgUrl      = book.ImgUrl;
            authorBuyBook.bookExtended.Year        = book.Year;
            authorBuyBook.bookExtended.Description = book.Description;
            Link link = db.Links.FirstOrDefault(z => z.BookId == bookId && z.AuthorId == authorId);

            authorBuyBook.bookExtended.Price = link.Price;
            authorBuyBook.bookExtended.Units = link.InStock;
            authorBuyBook.BookId             = link.BookId;
            authorBuyBook.AuthorId           = link.AuthorId;
            return(View(authorBuyBook));
        }