/*
 *      public CustomerContactPersonEntity GetCustomerContactPerson(int customerContactPersonID)
 *      {
 *          try
 *          {
 *              PersonBL personBL = new PersonBL();
 *
 *              DataSet ds = _customerContactPersonDA.GetCustomerContactPerson(customerContactPersonID);
 *              if ((ds.Tables != null) && (ds.Tables.Contains(SII.HCD.Administrative.Entities.TableNames.CustomerContactPersonTable)) && (ds.Tables[SII.HCD.Administrative.Entities.TableNames.CustomerContactPersonTable].Rows.Count > 0))
 *              {
 *                  int personID = SIIConvert.ToInteger(ds.Tables[SII.HCD.Administrative.Entities.TableNames.CustomerContactPersonTable].Rows[0]["PersonID"].ToString(), 0);
 *                  int contactTypeID = SIIConvert.ToInteger(ds.Tables[SII.HCD.Administrative.Entities.TableNames.CustomerContactPersonTable].Rows[0]["ContactTypeID"].ToString(), 0);
 *
 *                  DataSet ds2;
 *
 #region Contact Types
 *                  ds2 = _contactTypeDA.GetContactTypeByID(contactTypeID);
 *                  if ((ds2 != null) && (ds2.Tables.Contains(SII.HCD.Administrative.Entities.TableNames.ContactTypeTable)))
 *                  {
 *                      DataTable dt = ds2.Tables[SII.HCD.Administrative.Entities.TableNames.ContactTypeTable].Copy();
 *                      ds.Tables.Add(dt);
 *                  }
 #endregion
 *
 #region Person
 *                  if (personID <= 0)
 *                  {
 *                      throw new Exception(Properties.Resources.ERROR_CustomerContactPersonNotFound);
 *                  }
 *                  SII.HCD.BackOffice.Entities.PersonEntity myPerson = personBL.GetPerson(personID);
 #endregion
 *
 *                  CustomerContactPersonAdvancedAdapter customerContactPersonAdapter = new CustomerContactPersonAdvancedAdapter();
 *                  CustomerContactPersonEntity result = customerContactPersonAdapter.GetInfo(ds.Tables[SII.HCD.Administrative.Entities.TableNames.CustomerContactPersonTable].Rows[0], ds);
 *                  result.Person = myPerson;
 *                  LOPDLogger.Write(EntityNames.CustomerContactPersonEntityName, customerContactPersonID, ActionType.View);
 *                  return result;
 *              }
 *              else
 *                  return null;
 *          }
 *          catch (Exception ex)
 *          {
 *              if (ExceptionPolicy.HandleException(ex, ExceptionPolicies.Service)) throw;
 *              return null;
 *          }
 *      }
 */
        public CustomerContactPersonEntity GetCustomerContactPerson(int customerContactPersonID)
        {
            try
            {
                #region Person
                PersonBL personBL = new PersonBL();
                int      personID = 0;
                personID = personBL.obtenerPersonID_From_CustomerContactPerson(customerContactPersonID);

                if (personID == 0)
                {
                    throw new Exception(Properties.Resources.ERROR_CustomerContactPersonNotFound);
                }
                PersonEntity myPerson   = null;
                var          HiloPerson = System.Threading.Tasks.Task.Factory.StartNew(() => myPerson = personBL.GetPerson(personID));
                #endregion

                DataSet ds = _customerContactPersonDA.GetCustomerContactPerson(customerContactPersonID);
                if ((ds.Tables != null) && (ds.Tables.Contains(Entities.TableNames.CustomerContactPersonTable)) && (ds.Tables[Entities.TableNames.CustomerContactPersonTable].Rows.Count > 0))
                {
                    DataSet ds2 = new DataSet();
                    foreach (DataTable oTabla in ds.Tables)
                    {
                        if (oTabla.Rows.Count > 0)
                        {
                            ds2.Tables.Add(oTabla.Copy());
                        }
                    }

                    CustomerContactPersonAdvancedAdapter customerContactPersonAdapter = new CustomerContactPersonAdvancedAdapter();
                    CustomerContactPersonEntity          result = customerContactPersonAdapter.GetInfo(ds.Tables[Entities.TableNames.CustomerContactPersonTable].Rows[0], ds2);
                    HiloPerson.Wait();
                    result.Person = myPerson;
                    LOPDLogger.Write(EntityNames.CustomerContactPersonEntityName, customerContactPersonID, ActionType.View);
                    ds2.Dispose();
                    ds.Dispose();
                    return(result);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                if (ExceptionPolicy.HandleException(ex, ExceptionPolicies.Service))
                {
                    throw;
                }
                return(null);
            }
        }