Ejemplo n.º 1
0
 public async Task <IActionResult> Edit([Bind("Id,Date,Amount,Seller,Quantity")] SalesRecord sale, string bookId)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var selectedBookId = int.Parse(bookId);
             var book           = _context.Book.FirstOrDefault(x => x.Id == selectedBookId);
             sale.Book = book;
             _context.Update(sale);
             await _context.SaveChangesAsync();
         }
         catch (DbUpdateConcurrencyException)
         {
             if (!SalesRecordExists(sale.Id))
             {
                 return(NotFound());
             }
             else
             {
                 throw;
             }
         }
         return(RedirectToAction(nameof(Index)));
     }
     return(View(sale));
 }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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);
        }