public IActionResult Customers() { CustWrapper newView = new CustWrapper(); newView.AllCustomers = dbContext.Customers.ToList(); return(View(newView)); }
public IActionResult AddCustomer(CustWrapper fromForm) { CustWrapper newView = new CustWrapper(); if (ModelState.IsValid) { if (dbContext.Customers.Any(c => c.CustomerName == fromForm.Customer.CustomerName)) { ModelState.AddModelError("Customer.CustomerName", "Customer already exists"); newView.AllCustomers = dbContext.Customers.ToList(); return(View("Customers", newView)); } dbContext.Add(fromForm.Customer); dbContext.SaveChanges(); return(RedirectToAction("Customers")); } newView.AllCustomers = dbContext.Customers.ToList(); return(View("Customers", newView)); }