Exemple #1
0
 public ActionResult GetData()
 {
     using (MedyDBEntities db = new MedyDBEntities())
     {
         List <Employee> emplist = db.Employees.ToList <Employee>();
         return(Json(new { data = emplist }, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #2
0
 public ActionResult Delete(int id)
 {
     using (MedyDBEntities db = new MedyDBEntities())
     {
         Employee emp = db.Employees.Where(x => x.employeeID == id).FirstOrDefault <Employee>();
         db.Employees.Remove(emp);
         db.SaveChanges();
         return(Json(new { success = true, message = "Employee deleted successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #3
0
 public ActionResult AddOrEdit(int id = 0)
 {
     if (id == 0)
     {
         return(View(new Employee()));
     }
     else
     {
         using (MedyDBEntities db = new MedyDBEntities())
         {
             return(View(db.Employees.Where(x => x.employeeID == id).FirstOrDefault <Employee>()));
         }
     }
 }
Exemple #4
0
 public ActionResult AddOrEdit(Employee emp)
 {
     using (MedyDBEntities db = new MedyDBEntities())
     {
         if (emp.employeeID == 0)
         {
             db.Employees.Add(emp);
             db.SaveChanges();
             return(Json(new { success = true, message = "Employee added successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             db.Entry(emp).State = EntityState.Modified;
             db.SaveChanges();
             return(Json(new { success = true, message = "Employee updated successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }