public ActionResult UpdateCustomer(int id) { ApplicationDbContext db = new ApplicationDbContext(); HomeIndexViewModel viewmodel = new HomeIndexViewModel(); viewmodel.Customers = db.Customers.Where(c => c.Id == id).ToList(); return View(viewmodel); }
public ActionResult NewCustomer(Customer newcustomer) { ApplicationDbContext db = new ApplicationDbContext(); HomeIndexViewModel viewmodel = new HomeIndexViewModel(); db.Customers.Add(newcustomer); db.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult DeleteCustomer(int id) { ApplicationDbContext db = new ApplicationDbContext(); HomeIndexViewModel viewmodel = new HomeIndexViewModel(); Customer deletecustomer = db.Customers.Find(id); db.Customers.Remove(deletecustomer); db.SaveChanges(); return RedirectToAction("Index"); }
public ActionResult Index(string searchString) { ApplicationDbContext db = new ApplicationDbContext(); HomeIndexViewModel viewmodel = new HomeIndexViewModel(); if (searchString != null) { viewmodel.Customers = db.Customers.Include("Orders") .Where(c => c.Name.Contains(searchString)) .ToList(); } else { viewmodel.Customers = db.Customers.ToList(); viewmodel.Orders = db.Orders.ToList(); } return View(viewmodel); }
public ActionResult UpdateCustomer(int id, Customer updatedcustomer) { ApplicationDbContext db = new ApplicationDbContext(); HomeIndexViewModel viewmodel = new HomeIndexViewModel(); Customer customer = new Customer(); customer = db.Customers.Find(id); customer.Name = updatedcustomer.Name; customer.Birthday = updatedcustomer.Birthday; db.SaveChanges(); return View(viewmodel); }