Esempio n. 1
0
        public async Task <IActionResult> Create([Bind("Id,Title,Price,Description,Author,Publisher,AmountBook")] Book book)
        {
            if (ModelState.IsValid)
            {
                _context.Add(book);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }
Esempio n. 2
0
        public async Task <bool> CreateSale(SalesRecord sale, int bookId)
        {
            if (sale == null)
            {
                return(false);
            }

            var book = _context.Book.FirstOrDefault(x => x.Id == bookId);

            if (book == null)
            {
                return(false);
            }

            sale.Book = book;

            _context.Add(sale);
            await _context.SaveChangesAsync();

            return(true);
        }