public List <DataContracts.Mapping.CityMappingRS> Get_City_Mapping(DataContracts.Mapping.CityMappingRQ RQ) { using (BAL.BL_Mapping obj = new BAL.BL_Mapping()) { return(obj.Get_City_Mapping(RQ)); } }
public List <DataContracts.Mapping.CityMappingRS> Get_City_Mapping(DataContracts.Mapping.CityMappingRQ RQ) { if (RQ.SourceCode.ToLower() == "TLGX".ToLower()) { try { _database = MongoDBHandler.mDatabase(); List <DataContracts.Mapping.CityMappingRS> result = new List <DataContracts.Mapping.CityMappingRS>(); var collection = _database.GetCollection <BsonDocument>("CityMapping"); FilterDefinition <BsonDocument> filter; filter = Builders <BsonDocument> .Filter.Empty; if (!string.IsNullOrWhiteSpace(RQ.TargetCode)) { filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCode", new BsonRegularExpression(new Regex(RQ.TargetCode, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCityCode)) { filter = filter & Builders <BsonDocument> .Filter.Regex("CityCode", new BsonRegularExpression(new Regex(RQ.SourceCityCode, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCityName)) { filter = filter & Builders <BsonDocument> .Filter.Regex("CityName", new BsonRegularExpression(new Regex(RQ.SourceCityName, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCountryCode)) { filter = filter & Builders <BsonDocument> .Filter.Regex("CountryCode", new BsonRegularExpression(new Regex(RQ.SourceCountryCode, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCountryName)) { filter = filter & Builders <BsonDocument> .Filter.Regex("CountryName", new BsonRegularExpression(new Regex(RQ.SourceCountryName, RegexOptions.IgnoreCase))); } var searchResult = collection.Find(filter).ToList(); foreach (var docs in searchResult) { DataContracts.Mapping.CityMappingRS subResult = new DataContracts.Mapping.CityMappingRS(); subResult.SourceCode = RQ.SourceCode; subResult.SourceName = RQ.SourceCode; subResult.SourceCityCode = RQ.SourceCityCode; subResult.SourceCityName = RQ.SourceCityName; subResult.SourceCountryCode = RQ.SourceCountryCode; subResult.SourceCountryName = RQ.SourceCountryName; subResult.TargetCode = RQ.TargetCode; subResult.TargetName = docs["SupplierName"].AsString; subResult.TargetCityCode = docs["SupplierCityCode"].AsString; subResult.TargetCityName = docs["SupplierCityName"].AsString; subResult.TargetCountryCode = docs["SupplierCountryCode"].AsString; subResult.TargetCountryName = docs["SupplierCountryName"].AsString; result.Add(subResult); } collection = null; _database = null; return(result); } catch (FaultException <DataContracts.ErrorNotifier> ex) { throw ex; } } else if (RQ.TargetCode.ToLower() == "TLGX".ToLower()) { try { _database = MongoDBHandler.mDatabase(); List <DataContracts.Mapping.CityMappingRS> result = new List <DataContracts.Mapping.CityMappingRS>(); var collection = _database.GetCollection <BsonDocument>("CityMapping"); FilterDefinition <BsonDocument> filter; filter = Builders <BsonDocument> .Filter.Empty; if (!string.IsNullOrWhiteSpace(RQ.SourceCode)) { filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCode", new BsonRegularExpression(new Regex(RQ.SourceCode, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCityCode)) { filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCityCode", new BsonRegularExpression(new Regex(RQ.SourceCityCode, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCityName)) { filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCityName", new BsonRegularExpression(new Regex(RQ.SourceCityName, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCountryCode)) { filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCountryCode", new BsonRegularExpression(new Regex(RQ.SourceCountryCode, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCountryName)) { filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCountryName", new BsonRegularExpression(new Regex(RQ.SourceCountryName, RegexOptions.IgnoreCase))); } var searchResult = collection.Find(filter).ToList(); foreach (var docs in searchResult) { DataContracts.Mapping.CityMappingRS subResult = new DataContracts.Mapping.CityMappingRS(); subResult.SourceCode = RQ.SourceCode; subResult.SourceName = docs["SupplierName"].AsString; subResult.SourceCityCode = RQ.SourceCityCode; subResult.SourceCityName = RQ.SourceCityName; subResult.SourceCountryCode = RQ.SourceCountryCode; subResult.SourceCountryName = RQ.SourceCountryName; subResult.TargetCode = RQ.TargetCode; subResult.TargetName = RQ.TargetCode; subResult.TargetCityCode = docs["CityCode"].AsString; subResult.TargetCityName = docs["CityName"].AsString; subResult.TargetCountryCode = docs["CountryCode"].AsString; subResult.TargetCountryName = docs["CountryName"].AsString; result.Add(subResult); } collection = null; _database = null; return(result); } catch (FaultException <DataContracts.ErrorNotifier> ex) { throw ex; } } else { try { _database = MongoDBHandler.mDatabase(); List <DataContracts.Mapping.CityMappingRS> result = new List <DataContracts.Mapping.CityMappingRS>(); var collection = _database.GetCollection <BsonDocument>("CityMapping"); FilterDefinition <BsonDocument> filter; filter = Builders <BsonDocument> .Filter.Empty; if (!string.IsNullOrWhiteSpace(RQ.SourceCode)) { filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCode", new BsonRegularExpression(new Regex(RQ.SourceCode, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCityCode)) { filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCityCode", new BsonRegularExpression(new Regex(RQ.SourceCityCode, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCityName)) { filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCityName", new BsonRegularExpression(new Regex(RQ.SourceCityName, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCountryCode)) { filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCountryCode", new BsonRegularExpression(new Regex(RQ.SourceCountryCode, RegexOptions.IgnoreCase))); } if (!string.IsNullOrWhiteSpace(RQ.SourceCountryName)) { filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCountryName", new BsonRegularExpression(new Regex(RQ.SourceCountryName, RegexOptions.IgnoreCase))); } var searchResult = collection.Find(filter).ToList(); if (searchResult != null) { if (searchResult.Count > 0) { string _TlgxCityCode = searchResult[0]["CityCode"].AsString; string _TlgxCityName = searchResult[0]["CityName"].AsString; string _TlgxCountryCode = searchResult[0]["CountryCode"].AsString; string _TlgxCountryName = searchResult[0]["CountryName"].AsString; filter = Builders <BsonDocument> .Filter.Empty; filter = filter & Builders <BsonDocument> .Filter.Regex("SupplierCode", new BsonRegularExpression(new Regex(RQ.TargetCode, RegexOptions.IgnoreCase))); filter = filter & Builders <BsonDocument> .Filter.Eq("CountryCode", _TlgxCountryCode); filter = filter & Builders <BsonDocument> .Filter.Eq("CountryName", _TlgxCountryName); filter = filter & Builders <BsonDocument> .Filter.Eq("CityCode", _TlgxCityCode); filter = filter & Builders <BsonDocument> .Filter.Eq("CityName", _TlgxCityName); var searchNewResult = collection.Find(filter).ToList(); foreach (var docs in searchNewResult) { DataContracts.Mapping.CityMappingRS subResult = new DataContracts.Mapping.CityMappingRS(); subResult.SourceCode = RQ.SourceCode; subResult.SourceName = searchResult[0]["SupplierName"].AsString; subResult.SourceCityCode = RQ.SourceCityCode; subResult.SourceCityName = RQ.SourceCityName; subResult.SourceCountryCode = RQ.SourceCountryCode; subResult.SourceCountryName = RQ.SourceCountryName; subResult.TargetCode = RQ.TargetCode; subResult.TargetName = docs["SupplierName"].AsString; subResult.TargetCityCode = docs["SupplierCityCode"].AsString; subResult.TargetCityName = docs["SupplierCityName"].AsString; subResult.TargetCountryCode = docs["SupplierCountryCode"].AsString; subResult.TargetCountryName = docs["SupplierCountryName"].AsString; result.Add(subResult); } } collection = null; _database = null; } return(result); } catch (FaultException <DataContracts.ErrorNotifier> ex) { throw ex; } } }