示例#1
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"));
 }
示例#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"));
     }
 }