public IActionResult Edit(CustomerEditDeleteModel model) { if (this.ModelState.IsValid) { this.customerService.UpdateCustomer(model); return(RedirectToAction("All", new { order = "ascending" })); } return(View(model)); }
public IActionResult Edit(int?id) { if (id is null) { return(NotFound()); } CustomerEditDeleteModel model = this.customerService.GetUserEditDeleteModelById(id); return(View(model)); }
public void UpdateCustomer(CustomerEditDeleteModel model) { if (!this.db.Customers.Any(c => c.Id == model.Id)) { return; } var customer = this.db.Customers.FirstOrDefault(c => c.Id == model.Id); bool isYoungDriver = (DateTime.Now - model.Birthday).Value.Days < (365 * 2); customer.Name = model.Name; customer.Birthday = model.Birthday; customer.IsYoungDriver = isYoungDriver; this.db.SaveChanges(); }