Vous êtes sur la page 1sur 2

Provider.ServiceProvider.

cs
/// <summary>
/// Get Country Details based on country code.
/// </summary>
/// <param name="countryCode">Country code</param>
/// <returns>Datatable consist country configurations.</returns>
public DataTable GetCountryData(string countryCode)
{
using (TraceManager loTraceManager = new
TraceManager("DG.Provider.DataLayer.GetCountryData"))
{
try
{
loTraceManager.AddInformation("Creating Database Connection
object.");

Database loDBConnection =
DBConnectionCertificate.GetDatabase();
using (DbCommand loDBCommand =
loDBConnection.GetStoredProcCommand(LOCATION_GETCOUNTRYDATA, countryCode, "en-US"))
{
loTraceManager.AddInformation("Before Execute query...");

DataSet data = loDBConnection.ExecuteDataSet(loDBCommand);


loTraceManager.AddInformation("Successfully executed
query.");
return data.Tables[0];
}

}
catch (FaultException<string>)
{
throw;
}
catch (Exception ex)
{
loTraceManager.AddInformation(ex.Message.ToString());
//Add various items to the Exception.Data dictionary:

ex.SetExceptionType(DG.ExceptionTools.Library.ExceptionTypeEnum.GeneralError);

ex.SetDataValue("Service StackTrace", ex.ToString());

//Export the Exception.Data dictionary as a JSON string to


return as the fault Detail:
string strFaultDetail = ex.ExportDataToJson();

//Throw a new FaultException:


throw new FaultException<string>(strFaultDetail, ex.Message);
}
}
}

--------------------------------------------------------------------

SearchRequestValidator.cs
private bool ValidateStreetAddress(StreetAddress address)
{
//ToDo: Check for Place ID
//return !string.IsNullOrEmpty(address.AddressLine1) && !
string.IsNullOrEmpty(address.CountryCode) && !
string.IsNullOrEmpty(address.PostalCode);
//DG.Provider.Library.LocationBLService.CountryData ;
DataTable countryZipCode = GetCountryData(address.CountryCode);
bool IsZipRequired;
if (countryZipCode != null && countryZipCode.Rows.Count > 0)
{
IsZipRequired = Convert.ToBoolean(countryZipCode.Rows[0]
["IsZipRequired"]);

if (Convert.ToBoolean(countryZipCode.Rows[0]["IsZipRequired"]) ==
true)
{
return !string.IsNullOrEmpty(address.AddressLine1) && !
string.IsNullOrEmpty(address.CountryCode) && !
string.IsNullOrEmpty(address.PostalCode);
}

}
return !string.IsNullOrEmpty(address.AddressLine1) && !
string.IsNullOrEmpty(address.CountryCode);
}

===================================================================================
=============

bool IsZipRequired;
DG.Location.Library.Location loc = new DG.Location.Library.Location();
DataTable countryZipCode = loc.GetCountryData(address.CountryCode);

if (countryZipCode != null && countryZipCode.Rows.Count > 0)


{
IsZipRequired = Convert.ToBoolean(countryZipCode.Rows[0]
["IsZipRequired"]);

if (IsZipRequired == true)
{
return !string.IsNullOrEmpty(address.AddressLine1) && !
string.IsNullOrEmpty(address.CountryCode) && !
string.IsNullOrEmpty(address.PostalCode);
}

}
return !string.IsNullOrEmpty(address.AddressLine1) && !
string.IsNullOrEmpty(address.CountryCode);

Vous aimerez peut-être aussi