// GET: Customer/Details/5
 public ActionResult Details(int id)
 {
     using (DbModels1 dbModel = new DbModels1())
     {
         return(View(dbModel.Customer.Where(x => x.Id == id).FirstOrDefault()));
     }
 }
 // GET: Customer
 public ActionResult Index()
 {
     using (DbModels1 dbModel = new DbModels1())
     {
         return(View(dbModel.Customer.ToList()));
     }
 }
Exemplo n.º 3
0
        public ActionResult AddOrEdit(User userModel)
        {
            using (DbModels1 dbModel1 = new DbModels1())
            {
                dbModel1.Users.Add(userModel);
                dbModel1.SaveChanges();
            }
            ModelState.Clear();

            return(View("AddOrEdit", new User()));
        }
        public ActionResult Edit(int id, Customer customer)
        {
            try
            {
                // TODO: Add update logic here
                using (DbModels1 dbModel = new DbModels1())
                {
                    dbModel.Entry(customer).State = System.Data.EntityState.Modified;
                    dbModel.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Create(Customer customer)
        {
            try
            {
                // TODO: Add insert logic here
                using (DbModels1 dbModel = new DbModels1())
                {
                    dbModel.Customer.Add(customer);
                    dbModel.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Delete(int id, FormCollection collection)
        {
            try
            {
                // TODO: Add delete logic here
                using (DbModels1 dbModel = new DbModels1())
                {
                    Customer customer = dbModel.Customer.Where(x => x.Id == id).FirstOrDefault();
                    dbModel.Customer.Remove(customer);
                    dbModel.SaveChanges();
                }

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