Exemple #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));
 }
Exemple #2
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Title,Price,Description,Author,Publisher,AmountBook")] Book book)
        {
            if (id != book.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(book);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!BookExists(book.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(book));
        }