Esempio n. 1
0
        public ActionResult Save(CustomerTable cus)
        {
            if (ModelState.IsValid)
            {
                using (OnboardingTaskEntities dc = new OnboardingTaskEntities())
                {
                    if (cus.customerId > 0)
                    {
                        //Edit
                        var v = dc.CustomerTables.Where(a => a.customerId == cus.customerId).FirstOrDefault();
                        if (v != null)
                        {
                            v.customerId = cus.customerId;

                            v.customerName    = cus.customerName;
                            v.customerAge     = cus.customerAge;
                            v.customerAddress = cus.customerAddress;
                        }
                    }
                    else
                    {
                        //Save
                        var customers = dc.CustomerTables.OrderBy(a => a.customerId).ToList();
                        dc.CustomerTables.Add(cus);
                    }
                    dc.SaveChanges();
                }
            }

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
 public ActionResult DeleteCustomer(int id)
 {
     using (OnboardingTaskEntities dc = new OnboardingTaskEntities())
     {
         var v = dc.CustomerTables.Where(a => a.customerId == id).FirstOrDefault();
         if (v != null)
         {
             dc.CustomerTables.Remove(v);
             dc.SaveChanges();
         }
     }
     return(RedirectToAction("Index"));
 }