public async Task <IActionResult> Create([Bind("Id,FullName,Email")] Customer customer) { if (ModelState.IsValid) { customer.Id = Guid.NewGuid(); _context.Add(customer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(customer)); }
public async Task <ActionResult> Add(Customer customer) { // after validation if (customer == null) { ModelState.AddModelError("EmptyCustomer", "The customer is empty"); return(View(customer)); } if (!ModelState.IsValid) { return(View(customer)); } if (customer.Id == default) { customer.Id = Guid.NewGuid(); } _db.Customers.Add(customer); await _db.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }