public static int Save(person personToSave)
        {
            int returnValue;
            returnValue = PersonDAL.Save(personToSave);

            return returnValue;
        }
        public static int Save(person personToSave)
        {
            int result = 0;
            ExecuteTypeEnum queryId = ExecuteTypeEnum.InsertItem;

            //Checks for valid personId - if exsitis, UPDATE else INSERT
            //10 Insert
            //20 Update
            if (personToSave.PersonId > 0)
                queryId = ExecuteTypeEnum.UpdateItem;

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("Usp_ExecutePerson", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@QueryId", queryId);
                    myCommand.Parameters.AddWithValue("@personId", personToSave.PersonId);


                    if (personToSave.FirstName != null)
                        myCommand.Parameters.AddWithValue("@FirstName", personToSave.FirstName);

                    if (personToSave.MiddleName != null)
                        myCommand.Parameters.AddWithValue("@MiddleName", personToSave.MiddleName);

                    if (personToSave.LastName != null)
                        myCommand.Parameters.AddWithValue("@LastName", personToSave.LastName);

                    if (personToSave.BirthDate != DateTime.MinValue)
                        myCommand.Parameters.AddWithValue("@BirthDate", personToSave.BirthDate);

                    if (personToSave.SocialSecurityNumber != null)
                        myCommand.Parameters.AddWithValue("@SocialSecurityNumber", personToSave.SocialSecurityNumber);

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

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

                    //get returned Value from stored procedure and return Id
                    result = (int)myCommand.Parameters["@returnValue"].Value;
                }
                myConnection.Close();
            }
            return result;
        }
        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);
        }
        private static person FillDataRecord(IDataRecord myDataRecord)
        {
            person myObject = new person();
            myObject.PersonId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("PersonId"));

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

            myObject.FirstName = myDataRecord.GetString(myDataRecord.GetOrdinal("FirstName"));

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

            myObject.LastName = myDataRecord.GetString(myDataRecord.GetOrdinal("LastName"));

            myObject.Gender = myDataRecord.GetString(myDataRecord.GetOrdinal("Gender"));

            myObject.BirthDate = myDataRecord.GetDateTime(myDataRecord.GetOrdinal("BirthDate"));

            myObject.SocialSecurityNumber = myDataRecord.GetString(myDataRecord.GetOrdinal("SocialSecurityNumber"));

            return myObject;
        }
Exemple #5
0
        private static void LessonClassObject()
        {
            person myFirstPerson = new person();//Instantiate
            myFirstPerson.FirstName = "Justin";
            myFirstPerson.LastName = "Bigham";
            myFirstPerson.Id = 99;
            System.Console.WriteLine(myFirstPerson.Id);
            System.Console.WriteLine(myFirstPerson.FirstName + " " + myFirstPerson.LastName);

            myFirstPerson = new person();

            myFirstPerson.FirstName = "Micheal";    ////2nd instance of Person
            myFirstPerson.LastName = "Jones";
            myFirstPerson.Id = 77;
            System.Console.WriteLine(myFirstPerson.Id);
            System.Console.WriteLine(myFirstPerson.FirstName + " " + myFirstPerson.LastName);


        }