Example #1
0
 // GET: Customer/Delete/5
 public ActionResult Delete(int id)
 {
     using (MVCCrudOperationsEntities dbModel = new MVCCrudOperationsEntities())
     {
         return(View(dbModel.Customers.Where(x => x.Id == id).FirstOrDefault()));
     }
 }
Example #2
0
 // GET: Customer/Index
 public ActionResult Index()
 {
     using (MVCCrudOperationsEntities dbModel = new MVCCrudOperationsEntities())
     {
         return(View(dbModel.Customers.ToList()));
     }
 }
Example #3
0
        public ActionResult Create(Customer customer)
        {
            try
            {
                using (MVCCrudOperationsEntities dbModel = new MVCCrudOperationsEntities())
                {
                    dbModel.Customers.Add(customer);
                    dbModel.SaveChanges();
                }

                // TODO: Add insert logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #4
0
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                using (MVCCrudOperationsEntities dbModel = new MVCCrudOperationsEntities())
                {
                    Customer customer = dbModel.Customers.Where(x => x.Id == id).FirstOrDefault();
                    dbModel.Customers.Remove(customer);
                    dbModel.SaveChanges();
                }

                // TODO: Add delete logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Example #5
0
        public ActionResult Edit(int id, Customer customer)
        {
            try
            {
                using (MVCCrudOperationsEntities dbModel = new MVCCrudOperationsEntities())
                {
                    dbModel.Entry(customer).State = EntityState.Modified;
                    dbModel.SaveChanges();
                }



                // TODO: Add update logic here

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