Exemplo n.º 1
0
 // GET: Employee
 public ActionResult Index()
 {
     using (DemoDBString db = new DemoDBString())
     {
         List <Employee> empList = db.Employees.ToList();
         return(View(empList));
     }
 }
Exemplo n.º 2
0
 public ActionResult Delete(int id)
 {
     using (DemoDBString db = new DemoDBString())
     {
         Employee emp = db.Employees.Where(x => x.Emp_Id == id).FirstOrDefault <Employee>();
         db.Employees.Remove(emp);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
Exemplo n.º 3
0
 public ActionResult AddOrEdit(Employee emp)
 {
     using (DemoDBString db = new DemoDBString())
     {
         if (emp.Emp_Id == 0)
         {
             db.Employees.Add(emp);
             db.SaveChanges();
         }
         else
         {
             db.Entry(emp).State = EntityState.Modified;
             db.SaveChanges();
         }
     }
     return(RedirectToAction("index"));
 }
Exemplo n.º 4
0
 public ActionResult AddOrEdit(int id = 0)
 {
     if (id == 0)
     {
         ViewBag.Message = "Add";
         return(View(new Employee()));
     }
     else
     {
         using (DemoDBString db = new DemoDBString())
         {
             Employee emp = db.Employees.Where(x => x.Emp_Id == id).FirstOrDefault <Employee>();
             ViewBag.Message = "Edit";
             return(View(emp));
         }
     }
 }