예제 #1
0
        public IActionResult Customers()
        {
            CustWrapper newView = new CustWrapper();

            newView.AllCustomers = dbContext.Customers.ToList();
            return(View(newView));
        }
예제 #2
0
        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));
        }