// To protect from overposting attacks, enable the specific properties you want to bind to. // For more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Customer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CustomerExists(Customer.ID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
public async Task EditCustomer(Customer newCustomer) { var customer = await _context.Customers .FirstOrDefaultAsync(x => x.Id == newCustomer.Id); if (customer == default(Customer)) { return; } _context.Attach(customer); customer.FirstName = newCustomer.FirstName; customer.LastName = newCustomer.LastName; customer.DateOfBirth = newCustomer.DateOfBirth; await _context.SaveChangesAsync(); }