コード例 #1
0
 public void Create(Employee employee)
 {
     using (StaffContext db = new StaffContext())
     {
         db.Employees.InsertOnSubmit(employee);
         db.SubmitChanges();
     }
 }
コード例 #2
0
 public Employee Get(int id)
 {
     using (StaffContext db = new StaffContext())
     {
         return((from c in db.Employees
                 where c.EmployeeID == id
                 select c).FirstOrDefault());
     }
 }
コード例 #3
0
        public void Delete(Employee employee)
        {
            using (StaffContext db = new StaffContext())
            {
                Employee empl = (from c in db.Employees
                                 where c.EmployeeID == employee.EmployeeID
                                 select c).FirstOrDefault();

                db.Employees.DeleteOnSubmit(empl);
                db.SubmitChanges();
            }
        }
コード例 #4
0
        public void Update(Employee employee)
        {
            using (StaffContext db = new StaffContext())
            {
                Employee emp = (from c in db.Employees
                                where c.EmployeeID == employee.EmployeeID
                                select c).FirstOrDefault();

                if (emp != null)
                {
                    emp.FirstName   = employee.FirstName;
                    emp.LastName    = employee.LastName;
                    emp.Position    = employee.Position;
                    emp.Salary      = employee.Salary;
                    emp.DateOfBirth = employee.DateOfBirth;
                }
                db.SubmitChanges();
            }
        }