Ejemplo n.º 1
0
 public static List<EmployeeWithSupervisorName> GetAllEmployeesWithSupervisors()
 {
     using (EmployeeDB employeeDB = new EmployeeDB())
     {
         return (from e in employeeDB.Custom_Employees_GetAllEmployeesWithSupervisors() select e).ToList();
     }
 }
Ejemplo n.º 2
0
 public static List<Employee> GetEmployeesByFilterParams(string lastName = "", 
     string firstName = "",string country = "", 
     string city = "", string region = "")
 {
     using (EmployeeDB employeeDB = new EmployeeDB())
     {
         return (from e in employeeDB.Custom_Employees_GetEmployeesByFilterParams
                 (city: city, firstName: firstName, lastName: lastName, country: country, region: region)
                 select e).ToList();
     }
 }
Ejemplo n.º 3
0
        public static bool DeleteEmployee(int employeeId)
        {
            //Validate Input
            if (employeeId <= EmployeeIdMinValue)
                throw (new ArgumentOutOfRangeException("employeeId"));

            using (EmployeeDB employeeDB = new EmployeeDB())
            {
                Employee employee = employeeDB.Employees.FirstOrDefault(empObj => empObj.EmployeeId == employeeId);
                employeeDB.DeleteObject(employee);
                int numberOfAffectedRows = employeeDB.SaveChanges();
                return (numberOfAffectedRows == 0 ? false : true);
            }
        }
Ejemplo n.º 4
0
        public static bool DeleteEmployee(Employee employeeToBeDeleted)
        {
            //Validate Input
            if (employeeToBeDeleted == null)
                throw (new ArgumentNullException("employeeToBeDeleted"));

            // Validate Primary key value
            if (employeeToBeDeleted.EmployeeId <= EmployeeIdMinValue)
                throw (new ArgumentOutOfRangeException("employeeToBeDeleted"));

            using (EmployeeDB employeeDB = new EmployeeDB())
            {
                employeeDB.DeleteObject(employeeToBeDeleted);
                int numberOfAffectedRows = employeeDB.SaveChanges();
                return (numberOfAffectedRows == 0 ? false : true);
            }
        }
Ejemplo n.º 5
0
        public static int CreateNewEmployee(Employee newEmployee)
        {
            // Validate Parameters
            if (newEmployee == null)
                throw (new ArgumentNullException("newEmployee"));

            // Validate Primary key value
            if (newEmployee.EmployeeId > EmployeeIdMinValue)
                throw (new ArgumentOutOfRangeException("newEmployee"));

            using (EmployeeDB employeeDB = new EmployeeDB())
            {
                employeeDB.AddObject(
                   EntityFrameworkUtility.GetEntitySetFullName(employeeDB, newEmployee), newEmployee);
                employeeDB.SaveChanges();
                //employeeDB.AddToEmployees(newEmployee);
                return newEmployee.EmployeeId;
            }
        }
Ejemplo n.º 6
0
        public static bool DeleteEmployees(Collection<int> employeesIdsToDelete)
        {
            //Validate Input
            foreach (int employeeId in employeesIdsToDelete)
                if (employeeId <= EmployeeIdMinValue)
                    throw (new ArgumentOutOfRangeException("employeesIdsToDelete"));

            //performing deletion operation //

            string xmlString = PrimaryKeyXMLFormatter.FormatXmlForIdArray(employeesIdsToDelete);

            using (EmployeeDB employeeDB = new EmployeeDB())
            {
                int numberOfAffectedRows = (int)employeeDB.Employees_DeleteEmployees(xmlString).ToList()[0];
                return (numberOfAffectedRows == employeesIdsToDelete.Count ? true : false);
            }
        }
Ejemplo n.º 7
0
        public static bool UpdateEmployee(Employee updatedEmployee)
        {
            // Validate Parameters
            if (updatedEmployee == null)
                throw (new ArgumentNullException("updatedEmployee"));

            // Validate Primary key value
            if (updatedEmployee.EmployeeId <= EmployeeIdMinValue)
                throw (new ArgumentOutOfRangeException("updatedEmployee"));

            using (EmployeeDB employeeDB = new EmployeeDB())
            {
                Employee employee = employeeDB.Employees.FirstOrDefault(empObj => empObj.EmployeeId == updatedEmployee.EmployeeId);

                employee.FirstName = updatedEmployee.FirstName;
                employee.LastName = updatedEmployee.LastName;
                employee.HireDate = updatedEmployee.HireDate;
                employee.HomePhone = updatedEmployee.HomePhone;
                employee.Notes = updatedEmployee.Notes;
                employee.Photo = updatedEmployee.Photo;
                employee.PhotoPath = updatedEmployee.PhotoPath;
                employee.PostalCode = updatedEmployee.PostalCode;
                employee.Region = updatedEmployee.Region;
                employee.ReportsTo = updatedEmployee.ReportsTo;
                employee.Title = updatedEmployee.Title;
                employee.TitleOfCourtesy = updatedEmployee.TitleOfCourtesy;
                employee.Address = updatedEmployee.Address;
                employee.BirthDate = updatedEmployee.BirthDate;
                employee.City = updatedEmployee.City;
                employee.Country = updatedEmployee.Country;
                employee.Extension = updatedEmployee.Extension;

                int numberOfAffectedRows = employeeDB.SaveChanges();

                //returns the number of affected rows
                return (numberOfAffectedRows == 0 ? false : true);
            }
        }
Ejemplo n.º 8
0
        public static List<Employee> GetEmployeesByReportsToPaged(int? reportsTo, string orderBy, int startRowIndex, int maximumRows)
        {
            //Validate Input
            if (reportsTo == null)
                return GetAllEmployeesPaged(orderBy, startRowIndex, maximumRows);
            else if (reportsTo <= Employee.EmployeeIdMinValue)
                throw (new ArgumentOutOfRangeException("reportsTo"));

            //If there is no sorting parameter, then by default consider the primary key as the sorting field
            if (string.IsNullOrEmpty(orderBy))
                orderBy = "EmployeeId";

            using (EmployeeDB employeeDB = new EmployeeDB())
            {
                return (from employee in employeeDB.Employees
                        where employee.ReportsTo == reportsTo
                        orderby employee.EmployeeId //need a string support
                        select employee).Skip(startRowIndex).Take(maximumRows).ToList();
            }
        }
Ejemplo n.º 9
0
        public static int GetEmployeesByReportsToPagedCount(int? reportsTo, string orderBy, int startRowIndex, int maximumRows)
        {
            //Validate Input
            if (reportsTo == null)
                return GetAllEmployeesPagedCount(orderBy, startRowIndex, maximumRows);
            else if (reportsTo <= Employee.EmployeeIdMinValue)
                throw (new ArgumentOutOfRangeException("reportsTo"));

            using (EmployeeDB employeeDB = new EmployeeDB())
            {
                return (from employee in employeeDB.Employees
                        where employee.ReportsTo == reportsTo
                        select employee).Count();
            }
        }
Ejemplo n.º 10
0
        public static List<Employee> GetEmployeesByReportsTo(int? reportsTo)
        {
            //Validate Input
            if (reportsTo == null)
                return GetAllEmployees();
            else if (reportsTo <= Employee.EmployeeIdMinValue)
                throw (new ArgumentOutOfRangeException("reportsTo"));

            using (EmployeeDB employeeDB = new EmployeeDB())
            {
                return (from employee in employeeDB.Employees
                        where employee.ReportsTo == reportsTo
                            select employee).ToList();
            }
        }
Ejemplo n.º 11
0
        public static Employee GetEmployeeByEmployeeId(int employeeId)
        {
            //Validate Input
            if (employeeId <= EmployeeIdMinValue)
                throw (new ArgumentOutOfRangeException("employeeId"));

            using (EmployeeDB employeeDB = new EmployeeDB())
            {
                return (employeeDB.Employees.FirstOrDefault(empObj => empObj.EmployeeId == employeeId));
                //return employeeDB.Employees_GetEmployeeByEmployeeId(employeeId).ToList()[0];
            }
        }
Ejemplo n.º 12
0
 public static int GetAllEmployeesPagedCount(string orderBy, int startRowIndex, int maximumRows)
 {
     using (EmployeeDB employeeDB = new EmployeeDB())
     {
         return (int)employeeDB.Employees_GetAllEmployees_Paged_Count().ToList()[0];
     }
 }
Ejemplo n.º 13
0
        public static List<Employee> GetAllEmployeesPaged(string orderBy, int startRowIndex, int maximumRows)
        {
            if (string.IsNullOrEmpty(orderBy))
                orderBy = "EmployeeId";

            using (EmployeeDB employeeDB = new EmployeeDB())
            {
                return (from e in employeeDB.Employees_GetAllEmployees_Paged(orderBy, startRowIndex, maximumRows) select e).ToList();
            }
        }
Ejemplo n.º 14
0
 public static List<Employee> GetAllEmployees()
 {
     using (EmployeeDB employeeDB = new EmployeeDB())
     {
         return (from e in employeeDB.Employees_GetAllEmployees() select e).ToList();
     }
 }