예제 #1
0
        public static Employee Factory_CreateFreshEmployeeObjectWithValidSampleData()
        {
            Employee employee = new Employee();

            //------------------------------------

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

            //------------------------------------

            return employee;
        }
예제 #2
0
파일: EmployeeCL.cs 프로젝트: ZXLLPW/eisk
 public static int CreateNewEmployee(Employee newEmployee)
 {
     int result = Employee.CreateNewEmployee(newEmployee);
     //Invalidate the chache
     InvalidateCache();
     return result;
 }
 public void FirstName_PropertySetsValidValue_GetsSameValue()
 {
     Employee employee = new Employee();
     const string EXPECTED_FIRST_NAME = "Ashraf";
     employee.FirstName = EXPECTED_FIRST_NAME;
     string ACTUAL_FIRST_NAME = employee.FirstName;
     Assert.AreEqual(EXPECTED_FIRST_NAME, ACTUAL_FIRST_NAME, "First name has not been properly initialyzed via constructor.");
 }
예제 #4
0
        public static List<Employee> GetEmployeeCollectionFromReader(this IDataReader returnData)
        {
            List<Employee> colEmployee = new List<Employee>();

            while (returnData.Read())
            {
                Employee newEmployee = new Employee
                {
                    //required
                    EmployeeId = returnData["EmployeeId"] == System.DBNull.Value ? Employee.EmployeeIdMinValue : (Int32)returnData["EmployeeId"],
                    //required
                    LastName = returnData["LastName"] == System.DBNull.Value ? null : (String)returnData["LastName"],
                    //required
                    FirstName = returnData["FirstName"] == System.DBNull.Value ? null : (String)returnData["FirstName"],
                    //optional
                    Title = returnData["Title"] == System.DBNull.Value ? null : (String)returnData["Title"],
                    //optional
                    TitleOfCourtesy = returnData["TitleOfCourtesy"] == System.DBNull.Value ? null : (String)returnData["TitleOfCourtesy"],
                    //optional
                    BirthDate = returnData["BirthDate"] == System.DBNull.Value ? (DateTime?)null : (DateTime)returnData["BirthDate"],
                    //required
                    HireDate = returnData["HireDate"] == System.DBNull.Value ? DateTime.MinValue : (DateTime)returnData["HireDate"],
                    //required
                    Address = returnData["Address"] == System.DBNull.Value ? null : (String)returnData["Address"],
                    //optional
                    City = returnData["City"] == System.DBNull.Value ? null : (String)returnData["City"],
                    //optional
                    Region = returnData["Region"] == System.DBNull.Value ? null : (String)returnData["Region"],
                    //optional
                    PostalCode = returnData["PostalCode"] == System.DBNull.Value ? null : (String)returnData["PostalCode"],
                    //required
                    Country = returnData["Country"] == System.DBNull.Value ? null : (String)returnData["Country"],
                    //required
                    HomePhone = returnData["HomePhone"] == System.DBNull.Value ? null : (String)returnData["HomePhone"],
                    //optional
                    Extension = returnData["Extension"] == System.DBNull.Value ? null : (String)returnData["Extension"],
                    //optional
                    Photo = returnData["Photo"] == System.DBNull.Value ? null : (Byte[])returnData["Photo"],
                    //optional
                    Notes = returnData["Notes"] == System.DBNull.Value ? null : (String)returnData["Notes"],
                    //optional
                    ReportsTo = returnData["ReportsTo"] == System.DBNull.Value ? (Int32?)null : (Int32)returnData["ReportsTo"],
                    //optional
                    PhotoPath = returnData["PhotoPath"] == System.DBNull.Value ? null : (String)returnData["PhotoPath"],
                };

                //adding the Employee to the collection
                colEmployee.Add(newEmployee);
            }

            //returns the collection of Employee objects
            return (colEmployee);
        }
예제 #5
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);
            }
        }
예제 #6
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;
            }
        }
예제 #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);
            }
        }
예제 #8
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Employees EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToEmployees(Employee employee)
 {
     base.AddObject("Employees", employee);
 }
예제 #9
0
 /// <summary>
 /// Create a new Employee object.
 /// </summary>
 /// <param name="employeeId">Initial value of the EmployeeId property.</param>
 /// <param name="lastName">Initial value of the LastName property.</param>
 /// <param name="firstName">Initial value of the FirstName property.</param>
 /// <param name="hireDate">Initial value of the HireDate property.</param>
 /// <param name="address">Initial value of the Address property.</param>
 /// <param name="country">Initial value of the Country property.</param>
 /// <param name="homePhone">Initial value of the HomePhone property.</param>
 public static Employee CreateEmployee(global::System.Int32 employeeId, global::System.String lastName, global::System.String firstName, global::System.DateTime hireDate, global::System.String address, global::System.String country, global::System.String homePhone)
 {
     Employee employee = new Employee();
     employee.EmployeeId = employeeId;
     employee.LastName = lastName;
     employee.FirstName = firstName;
     employee.HireDate = hireDate;
     employee.Address = address;
     employee.Country = country;
     employee.HomePhone = homePhone;
     return employee;
 }
예제 #10
0
파일: EmployeeCL.cs 프로젝트: ZXLLPW/eisk
        public static bool UpdateEmployee(Employee updatedEmployee)
        {
            bool result = Employee.UpdateEmployee(updatedEmployee);
            //Invalidate the chache
            InvalidateCache();

            return result; ;
        }