예제 #1
0
        public static int Save(EmployeeBO employeeToSave)
        {
            //first need to save information and get Id
            int personId = SavePerson(employeeToSave);
            employeeToSave.PersonId = personId;

            //call DAL to save employy info
            return EmployeeDAL.Save(employeeToSave);
        }
예제 #2
0
        public static int Save(EmployeeBO employeeToSave)
        {
            int result = 0;
            ExecuteTypeEnum queryId = ExecuteTypeEnum.InsertItem;

            //check for Valid Person - if existis, UPDATE else INSERT
            // 10 = INSERT_ITEM
            //20 = UPDATE_ITEM

            if (employeeToSave.EmployeeId > 0)
                queryId = ExecuteTypeEnum.UpdateItem;

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_ExecuteEmployee", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@queryId", queryId);
                    myCommand.Parameters.AddWithValue("@personId", employeeToSave.PersonId);
                    myCommand.Parameters.AddWithValue("@employeeId", employeeToSave.EmployeeId);

                    if (employeeToSave.HireDate != DateTime.MinValue)
                        myCommand.Parameters.AddWithValue("@HireDate", employeeToSave.HireDate);

                    if (employeeToSave.TermDate != DateTime.MinValue)
                        myCommand.Parameters.AddWithValue("@termDate", employeeToSave.TermDate);

                    if (employeeToSave.PayRate > 0)
                        myCommand.Parameters.AddWithValue("@payrate", employeeToSave.PayRate);

                    if (employeeToSave.Background != null)
                        myCommand.Parameters.AddWithValue("@background", employeeToSave.Background);

                    // COMPLEX PROPERTIES
                    // check to see if the object is NULL if it is SHORT CIRCUT!
                    if (employeeToSave.Category != null && employeeToSave.Category.EntityTypeId > 0)
                        myCommand.Parameters.AddWithValue("@category", employeeToSave.Category.EntityTypeId);

                    if (employeeToSave.TierLevel != null && employeeToSave.TierLevel.EntityTypeId > 0)
                        myCommand.Parameters.AddWithValue("@tierlevel", employeeToSave.TierLevel.EntityTypeId);

                    if (employeeToSave.Laptop != null && employeeToSave.Laptop.EntityTypeId > 0)
                        myCommand.Parameters.AddWithValue("@laptop", employeeToSave.Laptop.EntityTypeId);

                    //add return Output parameter to command object
                    myCommand.Parameters.Add(HelperDAL.GetReturnParameterInt("returnValue"));

                    myConnection.Open();
                    myCommand.ExecuteNonQuery();

                    //get return Value from stored Procedure and return ID
                    result = (int)myCommand.Parameters["@returnValue"].Value;
                }
                myConnection.Close();
            }
            return result;
        }
예제 #3
0
        private static int SavePerson(EmployeeBO employeeToSave)
        {
            person tempPerson = new person();
            tempPerson.PersonId = employeeToSave.PersonId;

            if (employeeToSave.FirstName != null)
                tempPerson.FirstName = employeeToSave.FirstName;

            if (employeeToSave.MiddleName != null)
                tempPerson.MiddleName = employeeToSave.MiddleName;

            if (employeeToSave.LastName != null)
                tempPerson.LastName = employeeToSave.LastName;

            if (employeeToSave.SocialSecurityNumber != null)
                tempPerson.SocialSecurityNumber = employeeToSave.SocialSecurityNumber;

            if (employeeToSave.BirthDate != DateTime.MinValue)
                tempPerson.BirthDate = employeeToSave.BirthDate;

            //call PersonManager class to do the Save
            return PersonManager.Save(tempPerson);
        }
예제 #4
0
        private static void LessonInheritance()
        {
            EmployeeBO employeeJustin = new EmployeeBO();
            employeeJustin.FirstName = "Justin";
            employeeJustin.LastName = "Bigham";
            System.Console.WriteLine(employeeJustin.FirstName + " " + employeeJustin.LastName);

            EmployeeBO employeeAdrian = new EmployeeBO();
            employeeAdrian.FirstName = "Adrian";
            employeeAdrian.LastName = "Ratnayke";
            System.Console.WriteLine(employeeAdrian.FirstName + " " + employeeAdrian.LastName);

        }
예제 #5
0
        private static void LessonClassProperties()
        {


            EmployeeBO myEmployee = new EmployeeBO();
            myEmployee.Emails.Add(new EmailAddress { EmailAddressName = "*****@*****.**" });
            myEmployee.Emails.Add(new EmailAddress { EmailAddressName = "*****@*****.**" });
            myEmployee.Emails.Add(new EmailAddress { EmailAddressName = "[email protected]" });

            foreach (EmailAddress item in myEmployee.Emails)
            {
                System.Console.WriteLine(item.EmailAddressName);
            }
        }
예제 #6
0
        private static EmployeeBO FillDataRecord(IDataRecord myDataRecord)
        {
            EmployeeBO myObject = new EmployeeBO();
            myObject.EmployeeId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("EmployeeId"));
            myObject.PersonId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("PersonId"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("PayRate")))
                myObject.PayRate = myDataRecord.GetInt32(myDataRecord.GetOrdinal("PayRate"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("FirstName")))
                myObject.FirstName = myDataRecord.GetString(myDataRecord.GetOrdinal("FirstName"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("MiddleName")))
                myObject.MiddleName = myDataRecord.GetString(myDataRecord.GetOrdinal("MiddleName"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("LastName")))
                myObject.LastName = myDataRecord.GetString(myDataRecord.GetOrdinal("LastName"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("SocialSecurityNumber")))
                myObject.SocialSecurityNumber = myDataRecord.GetString(myDataRecord.GetOrdinal("SocialSecurityNumber"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Background")))
                myObject.Background = myDataRecord.GetString(myDataRecord.GetOrdinal("Background"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("DriverLicenseNumber")))
                myObject.DriversLicenseNumber = myDataRecord.GetString(myDataRecord.GetOrdinal("DriverLicenseNumber"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("BirthDate")))
                myObject.BirthDate = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("BirthDate"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("HireDate")))
                myObject.HireDate = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("HireDate"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("TermDate")))
                myObject.TermDate = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("TermDate"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("DriverLicenseExpireDate")))
                myObject.DriversLicenseExpireDate = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("DriverLicenseExpireDate"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("Category_EntityTypeId")))
                myObject.Category = new EntityType { EntityTypeId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("Category_EntityTypeId")) };

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("TeirLevel_EntityTypeId")))
                myObject.TierLevel = new EntityType { EntityTypeId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("TeirLevel_EntityTypeId")) };

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("LapTop_EntityId")))
                myObject.Laptop = new EntityType { EntityTypeId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("LapTop_EntityId")) };

            return myObject;
        }
        private void ProcessForm()
        {
            //instantiate a New stringBuilder Object to Hold/appeend Variable values to.
            //StringBuilder formControlValues = new StringBuilder();

            //assign New variables to the text box values.
            string firstName = FirstName.Text;
            string middleName = MiddleName.Text;
            string lastName = LastName.Text;
            string socialSecuritynumber = SSN.Text;


            DateTime birthDate = BirthDate.Text.ToDate();
            DateTime hireDate = HireDate.Text.ToDate();
            DateTime termDate = TermDate.Text.ToDate();

            //string catergoryText = Category.SelectedItem.Text;
            //string tierLevelText = TierLevel.SelectedItem.Text;
            string laptopText = Laptop.SelectedItem.Text;
            string background = Background.Text;

            int catergoryValue = Request.Form["EmployeeCategory"].ToInt();
            int tierLevelValue = Request.Form["EmployeeTierLevel"].ToInt();
            int laptopValue = Laptop.SelectedValue.ToInt();
            int payRate = PayRate.Text.ToInt();



            //set employee properties
            EmployeeBO employeeToSave = new EmployeeBO();

            //set IDs From hidden feild
            employeeToSave.EmployeeId = EmployeeId.Value.ToInt();
            employeeToSave.PersonId = PersonId.Value.ToInt();

            // person specific Info
            employeeToSave.FirstName = firstName;
            employeeToSave.MiddleName = middleName;
            employeeToSave.LastName = lastName;
            employeeToSave.SocialSecurityNumber = socialSecuritynumber;
            employeeToSave.BirthDate = birthDate;

            // Employee Specific Info
            employeeToSave.HireDate = hireDate;
            employeeToSave.TermDate = termDate;
            employeeToSave.PayRate = payRate;
            employeeToSave.Background = background;

            //Complex Properties
            employeeToSave.Category = new EntityType { EntityTypeId = catergoryValue };
            employeeToSave.TierLevel = new EntityType { EntityTypeId = tierLevelValue };
            employeeToSave.Laptop = new EntityType { EntityTypeId = laptopValue };


            //call middle tier to save person file
            int employeeId = EmployeeManager.Save(employeeToSave);

            #region Earlier Exercise
            //Appending the Values to StringBuilder "formcontrol"
            //formControlValues.Append("First Name: " + firstName);
            //formControlValues.Append("<br/>");
            //formControlValues.Append("Middle Name: " + middleName);
            //formControlValues.Append("<br/>");
            //formControlValues.Append("Last Name: " + lastName);
            //formControlValues.Append("<br/>");
            //formControlValues.Append("Birth Date: " + birthDate);
            //formControlValues.Append("<br/>");
            //formControlValues.Append("Social Security Number: " + socialSecuritynumber);
            //formControlValues.Append("<br/>");
            //formControlValues.Append("Hire Date: " + hireDate);
            //formControlValues.Append("<br/>");
            //formControlValues.Append("Term Date: " + termDate);
            //formControlValues.Append("<br/>");
            //formControlValues.Append("Category: " + catergoryText+" ("+catergoryValue+")");
            //formControlValues.Append("<br/>");
            //formControlValues.Append("Tier Level: " + tierLevelText+" ("+tierLevelValue+")");
            //formControlValues.Append("<br/>");
            //formControlValues.Append("Pay Rate: " + payRate);
            //formControlValues.Append("<br/>");
            //formControlValues.Append("Laptop Value: " + laptopText+" (" +laptopValue+")");
            //formControlValues.Append("<br/>");
            //formControlValues.Append("Background: " + background);
            //formControlValues.Append("<br/>");
            #endregion
            //outputs string to lable 
            if (employeeToSave.PersonId > 0 && employeeToSave.EmployeeId > 0)
            {
                this.DisplayLocalMessage("Update was Succesful!");
                EmployeeCategorySelectedId.Value = catergoryValue.ToString();
                EmployeeTierLevelSelectedId.Value = tierLevelValue.ToString();
            }
            else
            {
                //INSERT was succesful - redirect back 
                Response.Redirect("EmployeeBasic.aspx?EmployeeId=" + employeeId.ToString());
            }
        }