public static int Save(int employeeId, PhysicalAddress addressTosave)
       {
           int result = 0;
           ExecuteTypeEnum queryId = ExecuteTypeEnum.InsertItem;

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

           if (addressTosave.AddressId > 0)
               queryId = ExecuteTypeEnum.UpdateItem;

           using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
           {
               using (SqlCommand myCommand = new SqlCommand("usp_ExecuteAddress", myConnection))
               {
                   myCommand.CommandType = CommandType.StoredProcedure;
                   myCommand.Parameters.AddWithValue("@QueryId", queryId);
                   myCommand.Parameters.AddWithValue("@AddressId", addressTosave.AddressId);
                   //myCommand.Parameters.AddWithValue("@employeeId", employeeId);

                   if (addressTosave.ClientId > 0)
                       myCommand.Parameters.AddWithValue("@ClientId", addressTosave.ClientId);

                   if (addressTosave.PersonId > 0)
                       myCommand.Parameters.AddWithValue("@PersonId", addressTosave.PersonId);

                   if (addressTosave.AddressType.EntityTypeId >0)
                       myCommand.Parameters.AddWithValue("@EntityTypeId", addressTosave.AddressType.EntityTypeId);
                           
                   if (addressTosave.AddressNumber != null)
                       myCommand.Parameters.AddWithValue("@AddressNumber", addressTosave.AddressNumber);

                   if (addressTosave.Street != null)
                       myCommand.Parameters.AddWithValue("@Street", addressTosave.Street);

                   if (addressTosave.ZipCode != null)
                       myCommand.Parameters.AddWithValue("@ZipCode", addressTosave.ZipCode);

                   if (addressTosave.City != null)
                       myCommand.Parameters.AddWithValue("@City", addressTosave.City);
                   
                   if (addressTosave.StateId != null)
                       myCommand.Parameters.AddWithValue("@StateId", addressTosave.StateId);

                  //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;
       }
        private void ProcessAddress()
        {

            PhysicalAddress addressToSave = new PhysicalAddress();

           
            addressToSave.AddressNumber = AddressNumber.Text;
            addressToSave.Street = Street.Text;
            addressToSave.ZipCode = ZipCode.Text;
            addressToSave.City = City.Text;
            addressToSave.StateId = State.Text;

            addressToSave.AddressType = new EntityType { EntityTypeId = AddressTypeList.SelectedItem.Value.ToInt() };


            //Notes:    Set Id's from Hidden Values
            addressToSave.AddressId = AddressId.Value.ToInt();
            //addressToSave.ClientId = ClientId.Value.ToInt();
             EmployeeBO SlectedPerson = EmployeeManager.GetItem(base.EmployeeId);
               addressToSave.PersonId = SlectedPerson.PersonId;


            //Notes:    Call Manager to Save
            PhysicalAddressManager.Save(base.EmployeeId, addressToSave);

            //notes:    outputs string value to the label control
            if (addressToSave.AddressId > 0 && addressToSave.PersonId > 0)
            {
                //notes:    Update Successful
                Response.Redirect("Address.aspx?EmployeeId=" + _employeeId.ToString());
            }
            else
            {
                //Notes:    Insert successsful - redirect back
                Response.Redirect("Address.aspx?EmployeeId=" + _employeeId.ToString());
            }
        }
        private static PhysicalAddress FillDataRecord(IDataRecord myDataRecord)
        {
            PhysicalAddress myObject = new PhysicalAddress();

                       
            myObject.PersonId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("PersonId"));

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

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

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

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

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

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

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

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


            //entityType  AddressType

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("EntityTypeValue")))
                myObject.AddressType = new EntityType { EntityTypeValue = myDataRecord.GetString(myDataRecord.GetOrdinal("EntityTypeValue")) };

           
            return myObject;
        }
 public static int Save(int employeeId, PhysicalAddress addressTosave)
 {
     //call DAL to save employy info
     return PhysicalAddressDAL.Save(employeeId,addressTosave);
 }