示例#1
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);
            }
        }
示例#2
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);
            }
        }
示例#3
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;
            }
        }
示例#4
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);
            }
        }