コード例 #1
0
 public string AddEmployee(Employee Emp)
 {
     if (Emp != null)
     {
         using (SampleDBEntities2 dataContext = new SampleDBEntities2())
         {
             dataContext.Employees.Add(Emp);
             dataContext.SaveChanges();
             return("Employee Updated");
         }
     }
     else
     {
         return("Invalid Employee");
     }
 }
コード例 #2
0
 public string DeleteEmployee(Employee Emp)
 {
     if (Emp != null)
     {
         using (SampleDBEntities2 dataContext = new SampleDBEntities2())
         {
             int no           = Convert.ToInt32(Emp.Id);
             var employeeList = dataContext.Employees.Where(x => x.Id == no).FirstOrDefault();
             dataContext.Employees.Remove(employeeList);
             dataContext.SaveChanges();
             return("Employee Deleted");
         }
     }
     else
     {
         return("Invalid Employee");
     }
 }
コード例 #3
0
 public string UpdateEmployee(Employee Emp)
 {
     if (Emp != null)
     {
         using (SampleDBEntities2 dataContext = new SampleDBEntities2())
         {
             int no           = Convert.ToInt32(Emp.Id);
             var employeeList = dataContext.Employees.Where(x => x.Id == no).FirstOrDefault();
             employeeList.name = Emp.name;
             // employeeList.Age = Emp.Age;
             employeeList.email = Emp.email;
             dataContext.SaveChanges();
             return("Employee Updated");
         }
     }
     else
     {
         return("Invalid Employee");
     }
 }