public ActionResult BuyBook(PublisHouseBuyBook publisHouseBuyBook) { Link link = database.Links.FirstOrDefault(z => z.BookId == publisHouseBuyBook.BookId && z.PublishHouseId == publisHouseBuyBook.PublishHouseId); link.InStock = link.InStock - publisHouseBuyBook.UnitsBuy; database.SaveChanges(); return(Redirect("/PublishHouse")); }
public ActionResult BuyBook(string PublishHouseId, string BookId) { int publishHouseId = Int32.Parse(PublishHouseId); int bookId = Int32.Parse(BookId); PublisHouseBuyBook publisHouseBuyBook = new PublisHouseBuyBook(); publisHouseBuyBook.publishHouse = database.PublishHouses.FirstOrDefault(z => z.Id == publishHouseId); Book book = database.Books.FirstOrDefault(z => z.Id == bookId); publisHouseBuyBook.bookExtended = new BookExtended(); publisHouseBuyBook.bookExtended.Id = book.Id; publisHouseBuyBook.bookExtended.Name = book.Name; publisHouseBuyBook.bookExtended.ImgUrl = book.ImgUrl; publisHouseBuyBook.bookExtended.Year = book.Year; publisHouseBuyBook.bookExtended.Description = book.Description; Link link = database.Links.FirstOrDefault(z => z.BookId == bookId && z.PublishHouseId == publishHouseId); publisHouseBuyBook.bookExtended.Price = link.Price; publisHouseBuyBook.bookExtended.Units = link.InStock; publisHouseBuyBook.BookId = link.BookId; publisHouseBuyBook.PublishHouseId = link.PublishHouseId; return(View(publisHouseBuyBook)); }