示例#1
0
        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);
        }
示例#2
0
        public ActionResult NewCustomer(Customer newcustomer)
        {
            ApplicationDbContext db = new ApplicationDbContext();
            HomeIndexViewModel viewmodel = new HomeIndexViewModel();

            db.Customers.Add(newcustomer);
            db.SaveChanges();

            return RedirectToAction("Index");
        }
示例#3
0
        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");
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }