Пример #1
0
 public int? GetEmployeeIdByName(string name)
 {
     var firstLastName = new List<string>();
     if (string.IsNullOrEmpty(name))
         return null;
     firstLastName.AddRange(name.Split(' '));
     if (firstLastName.Count < 2)
         return null;
     string firstName = firstLastName[0];
     string lastName = firstLastName[1];
     if (!string.IsNullOrEmpty(firstName) && !string.IsNullOrEmpty(lastName))
     {
         using (var context = new HRServiceContext())
         {
             var employee = (from p
                                 in context.Employees
                             where p.FirstName.ToLower().Equals(firstName.ToLower()) && p.LastName.ToLower().Equals(lastName.ToLower())
                             select p).FirstOrDefault();
             if (employee != null)
                 return employee.EmployeeId;
             return null;
         }
     }
     return null;
 }
Пример #2
0
 public bool InsertEmployee(EmployeeSalary employeeSalary)
 {
     using (var db = new HRServiceContext())
     {
         db.Employees.Add(MapToEmployee(employeeSalary));
         db.SaveChanges();
         return true;
     }
 }
Пример #3
0
 public Employee GetEmployee(int id)
 {
     using (var context = new HRServiceContext())
     {
         var employee = (from p
                         in context.Employees
                         where p.EmployeeId == id
                         select p).FirstOrDefault();
         if (employee != null)
             return employee;
         throw new Exception("Invalid employee id");
     }
 }
Пример #4
0
 public List<EmployeeSalary> GetAllEmployees()
 {
     using (var context = new HRServiceContext())
     {
         var employeeSalary = from p
                                  in context.Employees
                              join t in context.Salaries on p.EmployeeId equals t.EmployeeId
                              select
                                  new EmployeeSalary
                                  {
                                      EmployeeId = p.EmployeeId,
                                      EmailAddress = p.EmailAddress,
                                      FirstName = p.FirstName,
                                      LastName = p.LastName,
                                      SupervisorId = p.SupervisorId,
                                      Salary = t.SalaryValue
                                  };
         return employeeSalary.ToList();
     }
 }