示例#1
0
 // GET: Customer/Delete/5
 public ActionResult Delete(int id)
 {
     using (Customer1Entities ce = new Customer1Entities())
     {
         return(View(ce.Customers.Where(x => x.Id == id).FirstOrDefault()));
     }
 }
示例#2
0
 // GET: Customer/Index
 public ActionResult Index()
 {
     using (Customer1Entities ce = new Customer1Entities())
     {
         return(View(ce.Customers.ToList()));
     }
 }
示例#3
0
 public ActionResult Edit(int id, Customer c)
 {
     try
     {
         // TODO: Add update logic here
         using (Customer1Entities ce = new Customer1Entities())
         {
             ce.Entry(c).State = EntityState.Modified;
             ce.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
示例#4
0
        public ActionResult Create(Customer c)
        {
            try
            {
                // TODO: Add insert logic here
                using (Customer1Entities ce = new Customer1Entities())
                {
                    ce.Customers.Add(c);
                    ce.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
示例#5
0
        public ActionResult Delete(int id, Customer customer)
        {
            try
            {
                // TODO: Add delete logic here
                using (Customer1Entities ce = new Customer1Entities())
                {
                    customer = ce.Customers.Where(x => x.Id == id).FirstOrDefault();
                    ce.Customers.Remove(customer);
                    ce.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }