示例#1
0
 public string DeleteEmployee(string employeeId)
 {
     if(!String.IsNullOrEmpty(employeeId))
     {
         try
         {
             int Id = Int32.Parse(employeeId);
             using (DemoContext contextObj = new DemoContext())
             {
                 var getEmployee = contextObj.employee.Find(Id);
                 contextObj.employee.Remove(getEmployee);
                 contextObj.SaveChanges();
                 return "Employee Deleted";
             }
         }
         catch (Exception ex)
         {
             return "Employee Not Found";
         }
     }
     else
     {
        return "Invalid Request";
     }
 }
示例#2
0
 public JsonResult GetAll()
 {
     using(DemoContext contextObj=new DemoContext())
     {
         var employeeList = contextObj.employee.ToList();
         return Json(employeeList,JsonRequestBehavior.AllowGet);
     }
 }
示例#3
0
 public JsonResult GetEmployeeById(string id)
 {
     using(DemoContext contextObj=new DemoContext())
      {
          int Id = Convert.ToInt32(id);
          var getEmployeeById = contextObj.employee.Find(Id);
          return Json(getEmployeeById,JsonRequestBehavior.AllowGet);
      }
 }
示例#4
0
 public string AddEmployee(Employee employee)
 {
     if(employee != null)
     {
         using (DemoContext contextObj = new DemoContext())
         {
             contextObj.employee.Add(employee);
             contextObj.SaveChanges();
             return "Employee Added";
         }
     }
     else
     {
         return "Invalid Record";
     }
 }
示例#5
0
 public string UpdateEmployee(Employee emp)
 {
     if(emp != null)
     {
         using (DemoContext contextObj = new DemoContext())
         {
             int empId = Convert.ToInt32(emp.Id);
             Employee employee = contextObj.employee.Where(a => a.Id == empId).FirstOrDefault();
             employee.Name = emp.Name;
             employee.Email = emp.Email;
             employee.Age = emp.Age;
             contextObj.SaveChanges();
             return "Employee Updated";
         }
     }
     else
     {
         return "Invalid Record";
     }
 }