public async Task <IActionResult> Edit(int id, [Bind("NewspaperLoanID,LoanDate,DevolutionDate,DevolutionDateMade,UserID,NewspaperID")] NewspaperLoan newspaperLoan) { if (id != newspaperLoan.NewspaperLoanID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(newspaperLoan); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NewspaperLoanExists(newspaperLoan.NewspaperLoanID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["UserID"] = new SelectList(_context.ApplicationUsers, "Id", "FirstName", newspaperLoan.UserID); ViewData["NewspaperID"] = new SelectList(_context.Newspapers, "NewspaperID", "CurrentPeriodicity", newspaperLoan.NewspaperID); return(View(newspaperLoan)); }
public async Task <IActionResult> Create(int id, [Bind("NewspaperLoanID,LoanDate,DevolutionDate,DevolutionDateMade,UserID,NewspaperID")] NewspaperLoan newspaperLoan) { if (ModelState.IsValid) { newspaperLoan.NewspaperID = id; newspaperLoan.LoanDate = DateTime.Now; newspaperLoan.DevolutionDateMade = DateTime.Now.AddDays(7); _context.Add(newspaperLoan); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["UserID"] = new SelectList(_context.ApplicationUsers, "Id", "FirstName", newspaperLoan.UserID); ViewData["NewspaperID"] = new SelectList(_context.Newspapers, "NewspaperID", "CurrentPeriodicity", newspaperLoan.NewspaperID); return(View(newspaperLoan)); }