public async Task <HttpResponseMessage> GetLocationMappingBySupplierCode(string SupplierCode) { try { List <SupplierZoneMaster> zoneMappingSearchResponses = new List <SupplierZoneMaster>(); _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <SupplierZoneMaster>("SupplierZoneMaster"); FilterDefinition <SupplierZoneMaster> filterForZone; filterForZone = Builders <SupplierZoneMaster> .Filter.Empty; if (!string.IsNullOrWhiteSpace(SupplierCode)) { filterForZone = filterForZone & Builders <SupplierZoneMaster> .Filter.Eq(b => b.Supplier_code, SupplierCode); } var result = await collection.Find(filterForZone).ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result); return(response); } catch (Exception ex) { NLogHelper.Nlogger_LogError.LogError(ex, this.GetType().FullName, Request.GetActionDescriptor().ActionName, Request.RequestUri.PathAndQuery); HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Server Error. Contact Admin. Error Date : " + DateTime.Now.ToString()); return(response); } }
public async Task <HttpResponseMessage> GetAccommodationByCountryCode(string CountryCode) { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <AccommodationMaster>("AccommodationMaster"); var result = await collection.Find(c => c.CountryCode == CountryCode.Trim().ToUpper() && c.TLGXAccoId != null) .Project(u => new AccommodationMasterGIATARS { HotelID = u.TLGXAccoId, HotelName = u.HotelName, HotelType = u.ProductCategorySubType, HotelStarRating = u.HotelStarRating, AddressStreet = concate(new List <string> { u.StreetName, u.Street3, u.Street4, u.Street5 }), PostalCode = u.PostalCode, GIATA_ID = "", CityName = u.CityName, TelephoneNumber = u.Telephone, FaxNumber = u.Fax, URL = u.WebSiteURL, EmailAddress = u.Email, Latitude = u.Latitude, Longitude = u.Longitude, CodeStatus = u.CodeStatus, AddressSuburb = u.SuburbDowntown } ) .SortBy(s => s.TLGXAccoId).ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result); return(response); }
public async Task <HttpResponseMessage> updateHolidayMapping(HolidayModel HolidayModel) { _database = MongoDBHandler.mDatabase(); IMongoCollection <HolidayModel> collectionHolidayModelMapping = _database.GetCollection <HolidayModel>("HolidayMapping"); if (HolidayModel != null) { FilterDefinition <HolidayModel> filter; filter = Builders <HolidayModel> .Filter.Empty; var nakshatraHolidayId = HolidayModel.NakshatraHolidayId.ToString().ToUpper(); filter = filter & Builders <HolidayModel> .Filter.Eq(x => x.NakshatraHolidayId, nakshatraHolidayId); var searchResult = await collectionHolidayModelMapping.Find(filter).FirstOrDefaultAsync(); // Update this record. if (searchResult != null) { searchResult = HolidayModel; var filter1 = Builders <HolidayModel> .Filter.Eq(c => c.NakshatraHolidayId, HolidayModel.NakshatraHolidayId); collectionHolidayModelMapping.ReplaceOne(filter, HolidayModel, new UpdateOptions { IsUpsert = true }); } HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, searchResult); return(response); } return(null); }
public async Task <HttpResponseMessage> GetListOfSupplierProductCodes(string SystemCityCode, string SupplierCode) { _database = MongoDBHandler.mDatabase(); IMongoCollection <ProductMapping> collectionProductMapping = _database.GetCollection <ProductMapping>("ProductMapping"); FilterDefinition <ProductMapping> filter; filter = Builders <ProductMapping> .Filter.Empty; filter = filter & Builders <ProductMapping> .Filter.Eq(x => x.SystemCityCode, SystemCityCode.Trim().ToUpper()); filter = filter & Builders <ProductMapping> .Filter.Eq(x => x.SupplierCode, SupplierCode.Trim().ToUpper()); var searchResult = await collectionProductMapping.Find(filter) .Project(x => new { x.SupplierProductCode }) .ToListAsync(); var searchResultArray = searchResult.Select(x => x.SupplierProductCode).Distinct().ToArray(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, searchResultArray); return(response); }
public async Task <HttpResponseMessage> GetProductDetailsBy_SuppName_SupHtlId_Format(string spname, string id, string format) { _database = MongoDBHandler.mDatabase(); var accomodationsList = _database.GetCollection <HotelsHotel>("Accommodations"); var productMappingList = _database.GetCollection <ProductMapping>("ProductMapping"); //FilterDefinition<HotelsHotel> filterAcco; //FilterDefinition<ProductMapping> filterPM; var idList = id.Split(','); XDocument doc = new XDocument(); doc.Add(new XElement("Hotels")); Hotels _Hotels = new Hotels(); List <HotelsHotel> _HotelsHotel = new List <HotelsHotel>(); foreach (var hotelId in idList) { var searchResultPM = await productMappingList.Find(x => (x.SupplierCode.ToLower() == spname.ToLower() && x.SupplierProductCode.ToLower() == hotelId.ToLower())).ToListAsync(); foreach (var resultPM in searchResultPM) { var searchResultAcco = await accomodationsList.Find(x => (x.HotelId.ToLower() == resultPM.SystemProductCode.ToLower())).ToListAsync(); foreach (var hotel in searchResultAcco) { hotel.SupplierHotelID = hotelId; _HotelsHotel.Add(hotel); } } } _Hotels.Hotel = _HotelsHotel; HttpResponseMessage response = new HttpResponseMessage(); if (format.ToLower() == "xml") { StringWriter sw = new StringWriter(); XmlTextWriter tw = null; XmlSerializer serializer = new XmlSerializer(_Hotels.GetType()); tw = new XmlTextWriter(sw); serializer.Serialize(tw, _Hotels); sw.Close(); if (tw != null) { tw.Close(); } response.Content = new StringContent(sw.ToString(), Encoding.UTF8, "application/xml"); response.StatusCode = HttpStatusCode.OK; } else if (format.ToLower() == "json") { response = Request.CreateResponse(HttpStatusCode.OK, _Hotels, "application/json"); } response.StatusCode = HttpStatusCode.OK; return(response); }
public async Task <HttpResponseMessage> GetProductDetailsBy_SuppName_SupCityName(string spname, string city) { _database = MongoDBHandler.mDatabase(); var accomodationsList = _database.GetCollection <HotelsHotel>("Accommodations"); var productMappingList = _database.GetCollection <ProductMapping>("ProductMapping"); var idList = await productMappingList.Find(x => (x.SupplierCode.ToLower() == spname.ToLower() && x.SupplierCityName.ToLower() == city.ToLower())).ToListAsync(); XDocument doc = new XDocument(); doc.Add(new XElement("Hotels")); Hotels _Hotels = new Hotels(); List <HotelsHotel> _HotelsHotel = new List <HotelsHotel>(); foreach (var hotelId in idList) { var searchResultAcco = await accomodationsList.Find(x => (x.HotelId.ToLower() == hotelId.SystemProductCode.ToLower())).ToListAsync(); foreach (var hotel in searchResultAcco) { hotel.SupplierHotelID = hotelId.SupplierProductCode; _HotelsHotel.Add(hotel); } } _Hotels.Hotel = _HotelsHotel; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, _Hotels); return(response); }
public async Task <HttpResponseMessage> GetSupplierCountryMappingByCode(string CountryCode, string SupplierCode) { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <CountryMapping>("CountryMapping"); FilterDefinition <CountryMapping> filter; filter = Builders <CountryMapping> .Filter.Empty; filter = filter & Builders <CountryMapping> .Filter.Eq(x => x.CountryCode, CountryCode.Trim().ToUpper()); filter = filter & Builders <CountryMapping> .Filter.Eq(x => x.SupplierCode, SupplierCode.Trim().ToUpper()); var searchResult = await collection.Find(filter) .Project(x => new CountryMapping_RS { CountryName = x.CountryName, CountryCode = x.CountryCode, SupplierName = x.SupplierName, SupplierCode = x.SupplierCode, SupplierCountryCode = x.SupplierCountryCode, SupplierCountryName = x.SupplierCountryName, MapId = x.MapId }) .ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, searchResult); return(response); }
public async Task <HttpResponseMessage> GetContinentByContinentCode(string ContinentCode) { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <Country>("CountryMaster"); var result = await collection.Find(c => c.ContinentCode == ContinentCode.Trim().ToUpper()).SortBy(s => s.CountryName).ToListAsync(); return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public async Task <HttpResponseMessage> GetAllContries() { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <Country>("CountryMaster"); var result = await collection.Find(bson => true).SortBy(s => s.CountryName).ToListAsync(); return(Request.CreateResponse(HttpStatusCode.OK, result)); }
public async Task <HttpResponseMessage> GetLocationMappingByCode(string ZoneCode, string SupplierCode) { try { List <ZoneMappingSearchResponse> zoneMappingSearchResponses = new List <ZoneMappingSearchResponse>(); _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <ZoneMaster>("ZoneMaster"); FilterDefinition <ZoneMaster> filterForZone; filterForZone = Builders <ZoneMaster> .Filter.Empty; if (!string.IsNullOrWhiteSpace(ZoneCode)) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.Eq(b => b.Zone_Code, ZoneCode); } var zoneMasters = await collection.Find(filterForZone).ToListAsync(); if (!string.IsNullOrWhiteSpace(SupplierCode)) { zoneMasters.ForEach(a => a.Zone_LocationMapping.RemoveAll(d => !(d.Supplier_code == SupplierCode))); } foreach (ZoneMaster zm in zoneMasters) { ZoneMappingSearchResponse zoneMappingSearchResponse = new ZoneMappingSearchResponse(); zoneMappingSearchResponse.ZoneCodes = zm.Zone_Code; List <string> SupplierCodes = zm.Zone_LocationMapping.Select(x => x.Supplier_code).Distinct().ToList(); List <Zone_Supplier> zone_Suppliers = new List <Zone_Supplier>(); foreach (string SupCode in SupplierCodes) { Zone_Supplier zone_Sup = new Zone_Supplier(); zone_Sup.SupplierCode = SupCode; List <Zone_LocationMapping> zone_LocationMappings = zm.Zone_LocationMapping.Where(x => x.Supplier_code == SupCode).ToList(); List <ZoneSupplierLocation> ZoneSupplierLocationList = zone_LocationMappings.ConvertAll(x => new ZoneSupplierLocation { Name = x.Name ?? string.Empty, Code = x.Code ?? string.Empty, Distance = x.Distance, Type = x.ZoneType ?? string.Empty, SubType = x.ZoneSubType ?? string.Empty, Latitude = x.Latitude, Longitude = x.Longitude, FullAddress = x.FullAdress }); zone_Sup.MappingLocations = ZoneSupplierLocationList; zone_Suppliers.Add(zone_Sup); } zoneMappingSearchResponse.SupplierCodes = zone_Suppliers; zoneMappingSearchResponses.Add(zoneMappingSearchResponse); } return(zoneMappingSearchResponses.Count > 0 ? Request.CreateResponse(HttpStatusCode.OK, zoneMappingSearchResponses) : Request.CreateResponse(HttpStatusCode.BadRequest, "Data Not Available for request")); } catch (Exception ex) { NLogHelper.Nlogger_LogError.LogError(ex, this.GetType().FullName, Request.GetActionDescriptor().ActionName, Request.RequestUri.PathAndQuery); HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Server Error. Contact Admin. Error Date : " + DateTime.Now.ToString()); return(response); } }
public async Task <HttpResponseMessage> GetPortByCountryCode(string CountryCode) { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <Port>("PortMaster"); var result = await collection.Find(c => c.oag_inactive_indicator != "I" && c.oag_country_code.ToUpper() == CountryCode.Trim().ToUpper()).SortBy(s => s.oag_port_name).ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result); return(response); }
public async Task <HttpResponseMessage> GetAllPorts() { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <Port>("PortMaster"); var result = await collection.Find(c => c.oag_inactive_indicator != "I").SortBy(s => s.oag_port_name).ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result); return(response); }
public async Task <HttpResponseMessage> GetAllStates() { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <State>("StateMaster"); var result = await collection.Find(c => true).SortBy(s => s.StateName).ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result); return(response); }
public async Task <HttpResponseMessage> GetZoneTypeMaster() { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <ZoneTypeMaster>("ZoneTypeMaster"); var result = await collection.Find(bson => true).SortBy(s => s.Zone_Type).ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result); return(response); }
public async Task <HttpResponseMessage> GetSupplierByName(string Name) { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <Supplier>("Supplier"); var result = await collection.Find(s => s.SupplierName == Name.Trim().ToUpper()).SortBy(s => s.SupplierCode).ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result); return(response); }
public async Task <HttpResponseMessage> GetActivityMasters() { _database = MongoDBHandler.mDatabase(); IMongoCollection <ActivityMasters> collectionActivity = _database.GetCollection <ActivityMasters>("ActivityMasters"); var searchResult = await collectionActivity.Find(s => true).SortBy(s => s.Type).ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, searchResult); return(response); }
public async Task <HttpResponseMessage> GetSystemProductMappingByCode(string SupplierProductCode, string SupplierCode) { _database = MongoDBHandler.mDatabase(); IMongoCollection <ProductMapping> collectionProductMapping = _database.GetCollection <ProductMapping>("ProductMapping"); FilterDefinition <ProductMapping> filter; filter = Builders <ProductMapping> .Filter.Empty; filter = filter & Builders <ProductMapping> .Filter.Eq(x => x.SupplierProductCode, SupplierProductCode.Trim().ToUpper()); filter = filter & Builders <ProductMapping> .Filter.Eq(x => x.SupplierCode, SupplierCode.Trim().ToUpper()); filter = filter & Builders <ProductMapping> .Filter.Or(Builders <ProductMapping> .Filter.Eq(x => x.MappingStatus, "MAPPED"), Builders <ProductMapping> .Filter.Eq(x => x.MappingStatus, "AUTOMAPPED")); //var searchResult = await collectionProductMapping.Find(filter) // .Project(x => new SystemProductMapping_RS // { // SupplierCode = x.SupplierCode, // MapId = x.MapId, // SupplierProductCode = x.SupplierProductCode, // SystemProductCode = x.SystemProductCode, // TlgxMdmHotelId = x.TlgxMdmHotelId // }) // .ToListAsync(); var searchResult = await collectionProductMapping.Find(filter) .Project(x => new CompleteProductMapping_RS { SupplierCode = x.SupplierCode, MapId = x.MapId, SupplierProductCode = x.SupplierProductCode, SystemProductCode = x.SystemProductCode, TlgxMdmHotelId = x.TlgxMdmHotelId, SupplierCityCode = x.SupplierCityCode, SupplierCityName = x.SupplierCityName, SupplierCountryCode = x.SupplierCountryCode, SupplierCountryName = x.SupplierCountryName, SupplierProductName = x.SupplierProductName, SystemCityCode = x.SystemCityCode, SystemCityName = x.SystemCityName, SystemCountryCode = x.SystemCountryCode, SystemCountryName = x.SystemCountryName, SystemProductName = x.SystemProductName, SystemProductType = x.SystemProductType }) .ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, searchResult); return(response); }
public async Task <HttpResponseMessage> GetVisaDetailByCountryCode(string CountryCode) { _database = MongoDBHandler.mDatabase(); IMongoCollection <DistributionWebApi.Models.VisaDefinition> collectionVisa = _database.GetCollection <DistributionWebApi.Models.VisaDefinition>("VisaMapping"); var filter = Builders <DistributionWebApi.Models.VisaDefinition> .Filter.ElemMatch(x => x.VisaDetail, x => x.CountryCode.ToLower() == CountryCode.ToLower()); var searchResult = await collectionVisa.Find(filter).FirstOrDefaultAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, searchResult); return(response); }
public async Task <HttpResponseMessage> GetProductByEzeegoId(string id) { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <HotelsHotel>("Accommodations"); var result = await collection.Find(c => c.HotelId == id).ToListAsync(); var hotels = new Hotels(); hotels.Hotel = result; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, hotels); return(response); }
public async Task <HttpResponseMessage> GetActivityDetailsByCode(int Code) { _database = MongoDBHandler.mDatabase(); IMongoCollection <ActivityDefinition> collectionActivity = _database.GetCollection <ActivityDefinition>("ActivityDefinitions"); FilterDefinition <ActivityDefinition> filter; filter = Builders <ActivityDefinition> .Filter.Empty; filter = filter & Builders <ActivityDefinition> .Filter.Eq(x => x.SystemActivityCode, Code); var searchResult = await collectionActivity.Find(filter).FirstOrDefaultAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, searchResult); return(response); }
public async Task <HttpResponseMessage> GetHolidayByNakshatraHolidayId(string NakshtraHolidayid) { _database = MongoDBHandler.mDatabase(); IMongoCollection <HolidayModel> collectionHolidayModelMapping = _database.GetCollection <HolidayModel>("HolidayMapping"); FilterDefinition <HolidayModel> filter; filter = Builders <HolidayModel> .Filter.Empty; //NakshtraHolidayid = NakshtraHolidayid.ToUpper(); filter = filter & Builders <HolidayModel> .Filter.Eq(x => x.NakshatraHolidayId, NakshtraHolidayid.TrimEnd().TrimStart()); var searchResult = await collectionHolidayModelMapping.Find(filter).FirstOrDefaultAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, searchResult); return(response); }
public async Task <HttpResponseMessage> GetActivityDetailsBySupplierAndProductCode(string SupplierCode, string ProductCode) { _database = MongoDBHandler.mDatabase(); IMongoCollection <ActivityDefinition> collectionActivity = _database.GetCollection <ActivityDefinition>("ActivityDefinitions"); FilterDefinition <ActivityDefinition> filter; filter = Builders <ActivityDefinition> .Filter.Empty; filter = filter & Builders <ActivityDefinition> .Filter.Eq(x => x.SupplierCompanyCode, SupplierCode.Trim().ToLower()); filter = filter & Builders <ActivityDefinition> .Filter.Eq(x => x.SupplierProductCode, ProductCode.Trim().ToUpper()); var searchResult = await collectionActivity.Find(filter).FirstOrDefaultAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, searchResult); return(response); }
public async Task <HttpResponseMessage> GetHolidayMappingByCode(string TourCode) { _database = MongoDBHandler.mDatabase(); if (!string.IsNullOrWhiteSpace(TourCode)) { IMongoCollection <BsonDocument> collectionHolidayMapping = _database.GetCollection <BsonDocument>("CKISHolidayData"); FilterDefinition <BsonDocument> filter; filter = Builders <BsonDocument> .Filter.Empty; // filter = filter & Builders<BsonDocument>.Filter.Eq("SupplierName",SupplierName); filter = filter & Builders <BsonDocument> .Filter.Eq("Holiday.Id", TourCode); var searchResult = await collectionHolidayMapping.Find(filter).ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, searchResult); return(response); } else { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid Reuest Parameters"); return(response); } }
public async Task <HttpResponseMessage> GetAllSupplierCityMappingByCode(string CityCode) { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <CityMapping>("CityMapping"); FilterDefinition <CityMapping> filter; filter = Builders <CityMapping> .Filter.Empty; filter = filter & Builders <CityMapping> .Filter.Regex(x => x.CityCode, new BsonRegularExpression(new Regex(CityCode, RegexOptions.IgnoreCase))); var searchResult = await collection.Find(filter) .Project(x => new SystemCityMapping_RS { SupplierCode = x.SupplierCode, MapId = x.MapId, SupplierCityCode = x.SupplierCityCode, }) .ToListAsync(); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, searchResult); return(response); }
public async Task <HttpResponseMessage> GetActivityByCountries(ActivitySearchByCountry_RQ param) { ActivitySearchResult resultList = new ActivitySearchResult(); if (param.PageSize > 100) { resultList.Message = "Page Size shouldn't be greater than 100."; return(Request.CreateResponse(HttpStatusCode.BadRequest, resultList)); } _database = MongoDBHandler.mDatabase(); string[] arrayOfStrings; if (!string.IsNullOrWhiteSpace(param.RequestingSupplierCode)) { //Get System Country Codes from Supplier Codes var collection = _database.GetCollection <BsonDocument>("CountryMapping"); FilterDefinition <BsonDocument> filterCountry; filterCountry = Builders <BsonDocument> .Filter.Empty; filterCountry = filterCountry & Builders <BsonDocument> .Filter.AnyIn("SupplierCountryCode", param.CountryCodes.Select(s => s.Trim().ToUpper()).Distinct()); filterCountry = filterCountry & Builders <BsonDocument> .Filter.Eq("SupplierCode", param.RequestingSupplierCode.Trim().ToUpper()); ProjectionDefinition <BsonDocument> projectCountry = Builders <BsonDocument> .Projection.Include("CountryCode").Exclude("_id"); var searchCountryResult = await collection.Find(filterCountry).Project(projectCountry).ToListAsync(); arrayOfStrings = searchCountryResult.Select(s => s["CountryCode"].AsString).ToArray(); } else { arrayOfStrings = param.CountryCodes.Select(s => s.Trim().ToUpper()).Distinct().ToArray(); } //get Activities IMongoCollection <BsonDocument> collectionActivity = _database.GetCollection <BsonDocument>("ActivityDefinitions"); FilterDefinition <BsonDocument> filter; filter = Builders <BsonDocument> .Filter.Empty; filter = filter & Builders <BsonDocument> .Filter.AnyIn("CountryCode", arrayOfStrings); if (param.FilterBySuppliers != null) { if (param.FilterBySuppliers.Length > 0) { filter = filter & Builders <BsonDocument> .Filter.AnyIn("SupplierCompanyCode", param.FilterBySuppliers.Select(s => s.Trim().ToLower())); } } var TotalRecords = await collectionActivity.Find(filter).CountDocumentsAsync(); List <ActivityDefinition> searchedData = new List <ActivityDefinition>(); if (TotalRecords != 0 && param.PageSize != 0) { SortDefinition <BsonDocument> sortByid = Builders <BsonDocument> .Sort.Ascending("_id"); var searchResult = await collectionActivity.Find(filter).Skip(param.PageSize * param.PageNo).Limit(param.PageSize).Sort(sortByid).ToListAsync(); //.Sort(sortByPrices) searchedData = JsonConvert.DeserializeObject <List <ActivityDefinition> >(searchResult.ToJson()); resultList.PageSize = param.PageSize; resultList.CurrentPage = param.PageNo; int remainder = (int)TotalRecords % param.PageSize; int quotient = (int)TotalRecords / param.PageSize; if (remainder > 0) { remainder = 1; } resultList.TotalPage = quotient + remainder; } else { resultList.TotalPage = 0; } resultList.CurrentPage = param.PageNo; resultList.TotalNumberOfActivities = TotalRecords; resultList.Activities = (from a in searchedData select new Activity { ActivityCode = a.SystemActivityCode, SupplierCompanyCode = a.SupplierCompanyCode, SupplierProductCode = a.SupplierProductCode, InterestType = a.InterestType, Category = a.Category, Type = a.Type, SubType = a.SubType, CategoryGroup = a.CategoryGroup, DisplayName = a.DisplayName ?? a.Name, Name = a.Name, Description = a.Description, DaysOfTheWeek = a.DaysOfTheWeek, PhysicalIntensity = a.PhysicalIntensity, Overview = a.Overview, Recommended = a.Recommended, CountryName = a.CountryName, CountryCode = a.CountryCode, CityName = a.CityName, CityCode = a.CityCode, StarRating = a.StarRating, NumberOfReviews = a.NumberOfReviews, NumberOfLikes = a.NumberOfLikes, NumberOfViews = a.NumberOfViews, ActivityMedia = a.ActivityMedia, DeparturePoint = a.DeparturePoint, ReturnDetails = a.ReturnDetails, ProductOptions = a.ProductOptions, NumberOfPassengers = a.NumberOfPassengers, Prices = a.Prices, SuitableFor = a.SuitableFor, Specials = a.Specials, SupplierCityDepartureCodes = a.SupplierCityDepartureCodes }).ToList(); foreach (var activity in searchedData) { var loadedActivity = resultList.Activities.Where(w => w.ActivityCode == activity.SystemActivityCode).First(); FilterDefinition <BsonDocument> filterForSimilarProducts; filterForSimilarProducts = Builders <BsonDocument> .Filter.Empty; filterForSimilarProducts = filterForSimilarProducts & Builders <BsonDocument> .Filter.Ne("_id", activity.SystemActivityCode); filterForSimilarProducts = filterForSimilarProducts & Builders <BsonDocument> .Filter.Eq("CityCode", activity.CityCode); filterForSimilarProducts = filterForSimilarProducts & Builders <BsonDocument> .Filter.AnyIn("ProductSubTypeId", activity.ProductSubTypeId); ProjectionDefinition <BsonDocument> project = Builders <BsonDocument> .Projection.Include("_id"); project = project.Include("Name"); project = project.Include("Categories"); project = project.Include("Prices"); project = project.Include("ProductOptions"); var SimilarProdSearchResult = await collectionActivity.Find(filterForSimilarProducts).Project(project).ToListAsync(); List <ActivityDefinition> SimilarProdSearchResultObj = JsonConvert.DeserializeObject <List <ActivityDefinition> >(SimilarProdSearchResult.ToJson()); if (SimilarProdSearchResultObj != null) { loadedActivity.SimliarProducts = SimilarProdSearchResultObj.Select(s => new SimliarProducts { SystemActivityCode = s.SystemActivityCode.ToString(), SystemActivityName = s.Name, CategoryGroup = s.CategoryGroup, Options = s.ProductOptions, Prices = s.Prices }).ToList(); } } return(Request.CreateResponse(HttpStatusCode.OK, resultList)); }
public async Task <HttpResponseMessage> GetProductByEzeegoIdandFormat(string id, string format) { _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <HotelsHotel>("Accommodations"); var result = await collection.Find(c => c.HotelId == id).ToListAsync(); HttpResponseMessage response = new HttpResponseMessage(); if (result == null || result.Count == 0) { if (format.ToLower() == "xml") { response.Content = new StringContent("<message>Zero Results.</message>", Encoding.UTF8, "application/xml"); response.StatusCode = HttpStatusCode.NotFound; } else if (format.ToLower() == "json") { response.Content = new StringContent("Zero Results.", Encoding.UTF8, "application/json"); response.StatusCode = HttpStatusCode.NotFound; } return(response); } var hotels = new Hotels(); hotels.Hotel = result; //XmlWriterSettings writerSettings = new XmlWriterSettings(); //writerSettings.OmitXmlDeclaration = true; //writerSettings.ConformanceLevel = ConformanceLevel.Fragment; //writerSettings.CloseOutput = false; //System.Text.StringBuilder localMemoryStream = new System.Text.StringBuilder(); //using (XmlWriter writer = XmlWriter.Create(localMemoryStream, writerSettings)) //{ // writer.WriteStartElement("Hotels"); // writer.WriteStartElement("Hotel"); // writer.WriteElementString("title", "A Programmer's Guide to ADO.NET"); // writer.WriteElementString("author", "Mahesh Chand"); // writer.WriteElementString("publisher", "APress"); // writer.WriteElementString("price", "44.95"); // writer.WriteEndElement(); // writer.Flush(); //} XDocument doc = new XDocument(); //doc.Add( // new XElement("Hotels", new XElement // ("Hotel", new XAttribute("SupplierHotelID", ""), new XElement("StarRating", new XAttribute("Level", 2))))); doc.Add(new XElement("Hotels")); foreach (var hotel in result) { doc.Element("Hotels").Add(new XElement("Hotel")); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("SupplierHotelID", string.Empty)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("HotelId", hotel.HotelId)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("name", hotel.name)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("credicards", hotel.credicards)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("areatransportation", hotel.credicards)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("restaurants", hotel.restaurants)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("meetingfacility", hotel.meetingfacility)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("description", hotel.description)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("highlight", hotel.highlight)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("overview", hotel.overview)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("checkintime", hotel.checkintime)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("checkouttime", hotel.checkouttime)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("email", hotel.email)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("website", hotel.website)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("rooms", hotel.rooms)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("LandmarkCategory", hotel.LandmarkCategory)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("Landmark", hotel.Landmark)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("theme", hotel.theme)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("HotelChain", hotel.HotelChain)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("BrandName", hotel.BrandName)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("recommends", hotel.recommends)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("latitude", hotel.latitude)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("longitude", hotel.longitude)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("LandmarkDescription", hotel.LandmarkDescription)); doc.Element("Hotels").Element("Hotel").Add(new XAttribute("thumb", hotel.thumb)); doc.Element("Hotels").Element("Hotel").Add(new XElement("StarRating")); doc.Element("Hotels").Element("Hotel").Element("StarRating").Add(new XAttribute("Level", hotel.StarRating.Level)); doc.Element("Hotels").Element("Hotel").Add(new XElement("Address")); doc.Element("Hotels").Element("Hotel").Element("Address").Add(new XAttribute("address", hotel.Address.address)); doc.Element("Hotels").Element("Hotel").Element("Address").Add(new XAttribute("city", hotel.Address.city)); doc.Element("Hotels").Element("Hotel").Element("Address").Add(new XAttribute("state", hotel.Address.state)); doc.Element("Hotels").Element("Hotel").Element("Address").Add(new XAttribute("country", hotel.Address.country)); doc.Element("Hotels").Element("Hotel").Element("Address").Add(new XAttribute("pincode", hotel.Address.pincode)); doc.Element("Hotels").Element("Hotel").Element("Address").Add(new XAttribute("location", hotel.Address.location)); doc.Element("Hotels").Element("Hotel").Element("Address").Add(new XAttribute("phone", hotel.Address.phone)); doc.Element("Hotels").Element("Hotel").Element("Address").Add(new XAttribute("fax", hotel.Address.fax)); foreach (var img in hotel.image) { doc.Element("Hotels").Element("Hotel").Add(new XElement("image", new XAttribute("path", img.path))); } doc.Element("Hotels").Element("Hotel").Add(new XElement("video")); doc.Element("Hotels").Element("Hotel").Add(new XElement("HotelFacility")); foreach (var facility in hotel.HotelFacility) { doc.Element("Hotels").Element("Hotel").Element("HotelFacility").Add(new XElement("Facility", new XAttribute("name", facility.name))); } doc.Element("Hotels").Element("Hotel").Add(new XElement("HotelAmenity")); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Restaurant", hotel.HotelAmenity.Restaurant ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("conference", hotel.HotelAmenity.conference ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("fitness", hotel.HotelAmenity.fitness ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("travel", hotel.HotelAmenity.travel ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("forex", hotel.HotelAmenity.forex ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("shopping", hotel.HotelAmenity.shopping ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("banquet", hotel.HotelAmenity.banquet ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("games", hotel.HotelAmenity.games ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Bar", hotel.HotelAmenity.Bar ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Coffee_Shop", hotel.HotelAmenity.Coffee_Shop ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Room_Service", hotel.HotelAmenity.Room_Service ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Internet_Access", hotel.HotelAmenity.Internet_Access ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Business_Centre", hotel.HotelAmenity.Business_Centre ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Swimming_Pool", hotel.HotelAmenity.Swimming_Pool ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Pets", hotel.HotelAmenity.Pets ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Tennis_Court", hotel.HotelAmenity.Tennis_Court ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Golf", hotel.HotelAmenity.Golf ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Air_Conditioning", hotel.HotelAmenity.Air_Conditioning ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Parking", hotel.HotelAmenity.Parking ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Wheel_Chair", hotel.HotelAmenity.Wheel_Chair ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Element("HotelAmenity").Add(new XAttribute("Health_Club", hotel.HotelAmenity.Health_Club ? 1 : 0)); doc.Element("Hotels").Element("Hotel").Add(new XElement("HotelDistance")); doc.Element("Hotels").Element("Hotel").Element("HotelDistance").Add(new XAttribute("DistancefromAirport", hotel.HotelDistance.DistancefromAirport ?? string.Empty)); doc.Element("Hotels").Element("Hotel").Element("HotelDistance").Add(new XAttribute("DistancefromStation", hotel.HotelDistance.DistancefromStation ?? string.Empty)); doc.Element("Hotels").Element("Hotel").Element("HotelDistance").Add(new XAttribute("DistancefromBus", hotel.HotelDistance.DistancefromBus ?? string.Empty)); doc.Element("Hotels").Element("Hotel").Element("HotelDistance").Add(new XAttribute("DistancefromCityCenter", hotel.HotelDistance.DistancefromCityCenter ?? string.Empty)); } if (format.ToLower() == "xml") { response.Content = new StringContent(doc.ToString(), Encoding.UTF8, "application/xml"); response.StatusCode = HttpStatusCode.OK; //response = Request.CreateResponse(HttpStatusCode.OK, localMemoryStream.ToString(), "application/xml"); } else if (format.ToLower() == "json") { response = Request.CreateResponse(HttpStatusCode.OK, hotels, "application/json"); } return(response); }
public async Task <HttpResponseMessage> SearchbyZoneMasterCode(ZoneMappingSearchRequest RQ) { try { List <ZoneMappingSearchResponse> zoneResult = new List <ZoneMappingSearchResponse>(); if (RQ.PageSize == 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Page Size should be greater than Zero.")); } else if (RQ.PageNo == 0) { RQ.PageNo = 1; } _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <ZoneMaster>("ZoneMaster"); FilterDefinition <ZoneMaster> filterForZone; filterForZone = Builders <ZoneMaster> .Filter.Empty; if (RQ.ZoneCodes.Any()) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.In(b => b.Zone_Code, RQ.ZoneCodes.Select(x => x.Trim().ToUpper())); var zoneMasters = await collection.Find(filterForZone).Skip((RQ.PageNo - 1) * RQ.PageSize).Limit(RQ.PageSize).ToListAsync(); if (RQ.SupplierCodes.Any()) { zoneMasters.ForEach(a => a.Zone_LocationMapping.RemoveAll(d => !(RQ.SupplierCodes.Contains(d.Supplier_code)))); } foreach (ZoneMaster zm in zoneMasters) { ZoneMappingSearchResponse zoneMappingSearchResponse = new ZoneMappingSearchResponse(); zoneMappingSearchResponse.ZoneCodes = zm.Zone_Code; List <string> SupplierCodes = zm.Zone_LocationMapping.Select(x => x.Supplier_code).Distinct().ToList(); List <Zone_Supplier> zone_Suppliers = new List <Zone_Supplier>(); foreach (string SupCode in SupplierCodes) { Zone_Supplier zone_Sup = new Zone_Supplier(); zone_Sup.SupplierCode = SupCode; List <Zone_LocationMapping> zone_LocationMappings = zm.Zone_LocationMapping.Where(x => x.Supplier_code == SupCode).ToList(); List <ZoneSupplierLocation> ZoneSupplierLocationList = zone_LocationMappings.ConvertAll(x => new ZoneSupplierLocation { Name = x.Name ?? string.Empty, Code = x.Code ?? string.Empty, Distance = x.Distance, Type = x.ZoneType ?? string.Empty, SubType = x.ZoneSubType ?? string.Empty, Latitude = x.Latitude, Longitude = x.Longitude, FullAddress = x.FullAdress }); zone_Sup.MappingLocations = ZoneSupplierLocationList; zone_Suppliers.Add(zone_Sup); } zoneMappingSearchResponse.SupplierCodes = zone_Suppliers; zoneResult.Add(zoneMappingSearchResponse); } return(zoneResult.Count > 0 ? Request.CreateResponse(HttpStatusCode.OK, zoneResult) : Request.CreateResponse(HttpStatusCode.BadRequest, "Data Not Available for request")); } else { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, "Zone Code Length must be greater than Zero"); return(response); } } catch (Exception ex) { NLogHelper.Nlogger_LogError.LogError(ex, this.GetType().FullName, Request.GetActionDescriptor().ActionName, Request.RequestUri.PathAndQuery); HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Server Error. Contact Admin. Error Date : " + DateTime.Now.ToString()); return(response); } }
public async Task <HttpResponseMessage> GetZones(ZoneSearchRQ RQ) { ZoneSearchRS zoneResult = new ZoneSearchRS(); if (RQ.PageSize == 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Page Size should be greater than Zero.")); } _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <ZoneMaster>("ZoneMaster"); FilterDefinition <ZoneMaster> filterForZone; filterForZone = Builders <ZoneMaster> .Filter.Empty; if (!string.IsNullOrWhiteSpace(RQ.Zone_name)) { if (RQ.Zone_name.Length >= 3) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.Regex(b => b.Zone_Name, new Regex("^" + RQ.Zone_name.Trim().ToUpper())); //like search //filterForZone = filterForZone & Builders<ZoneMaster>.Filter.Regex(b => b.Zone_Name, new BsonRegularExpression(new Regex(RQ.Zone_name.Trim(), RegexOptions.IgnoreCase))); if (!string.IsNullOrWhiteSpace(RQ.Zone_Type)) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.Eq(b => b.Zone_Type, RQ.Zone_Type.Trim().ToUpper()); } if (!string.IsNullOrWhiteSpace(RQ.Zone_SubType)) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.Eq(b => b.Zone_SubType, RQ.Zone_SubType.Trim().ToUpper()); } if (!string.IsNullOrWhiteSpace(RQ.SystemCountryCode)) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.Eq(b => b.TLGXCountryCode, RQ.SystemCountryCode.Trim().ToUpper()); } if (!string.IsNullOrWhiteSpace(RQ.Zone_Code)) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.Eq(b => b.Zone_Code, RQ.Zone_Code.Trim().ToUpper()); } var resultCount = await collection.Find(filterForZone).CountDocumentsAsync(); //TotalResultReturned int TotalSearchedZone = (int)resultCount; if (TotalSearchedZone > 0) { //for TotalPages in search result int remainder = TotalSearchedZone % RQ.PageSize; int quotient = TotalSearchedZone / RQ.PageSize; if (remainder > 0) { remainder = 1; } //end zoneResult.PageSize = RQ.PageSize; zoneResult.CurrentPage = RQ.PageNo; zoneResult.TotalNumberOfZones = TotalSearchedZone; zoneResult.TotalPage = quotient + remainder; var result = await collection.Find(filterForZone).Project(x => new ZoneInfo { ZoneId = x._id, TLGXCountryCode = x.TLGXCountryCode, Zone_Name = x.Zone_Name, Zone_SubType = x.Zone_SubType, Zone_Type = x.Zone_Type, Zone_Code = x.Zone_Code }).Skip(RQ.PageNo * RQ.PageSize).Limit(RQ.PageSize).ToListAsync(); zoneResult.Zones = result; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, zoneResult); return(response); } else { HttpResponseMessage res = Request.CreateResponse(HttpStatusCode.BadRequest, "No zone found for this filter criteria."); return(res); } } else { HttpResponseMessage res = Request.CreateResponse(HttpStatusCode.BadRequest, "ZoneName Should be atleast 3 chars"); return(res); } } else { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, "Invalid ZoneName"); return(response); } }
public async Task <HttpResponseMessage> GetZoneListByGeoPointBasis(ZoneSearchRequestForGeoPoint RQ) { try { List <ZoneSearchResponse> zoneResult = new List <ZoneSearchResponse>(); if (RQ.PageSize == 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Page Size should be greater than Zero.")); } else if (RQ.PageNo == 0) { RQ.PageNo = 1; } else if (RQ.ZoneGeoLocations.FirstOrDefault().Zone_Latitude == 0 || RQ.ZoneGeoLocations.FirstOrDefault().Zone_Longitude == 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Geo Location Format is not proper.")); } _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <ZoneMaster>("ZoneMaster"); FilterDefinition <ZoneMaster> filterForZone; filterForZone = Builders <ZoneMaster> .Filter.Empty; if (RQ.ZoneTypes.Any()) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.In(b => b.Zone_Type, RQ.ZoneTypes.Select(x => x.Zone_Type.Trim().ToUpper())); } if (RQ.Zone_SubType.Any()) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.In(b => b.Zone_SubType, RQ.Zone_SubType.Select(x => x.ZoneSub_Type.Trim().ToUpper())); } if (RQ.ZoneGeoLocations.Any()) { filterForZone = filterForZone & new BsonDocument() { { "loc", new BsonDocument() { { "$near", new BsonDocument() { { "$geometry", new BsonDocument() { { "type", "Point" }, { "coordinates", new BsonArray() { RQ.ZoneGeoLocations.FirstOrDefault().Zone_Longitude, RQ.ZoneGeoLocations.FirstOrDefault().Zone_Latitude } } } }, { "$minDistance", 0 }, { "$maxDistance", RQ.GeoDistance > 0?RQ.GeoDistance:0 } } } } } }; } var result = await collection.Find(filterForZone).Project(x => new ZoneSearchResponse { ZoneCode = x.Zone_Code, ZoneName = x.Zone_Name, ZoneSubType = x.Zone_SubType, ZoneType = x.Zone_Type, ZoneLocationPoint = new ZoneGeoLocationResponse { Zone_Latitude = x.Latitude, Zone_Longitude = x.Longitude }, Zone_GeographyMapping = x.Zone_GeographyMapping }).Skip((RQ.PageNo - 1) * RQ.PageSize).Limit(RQ.PageSize).ToListAsync(); zoneResult = result; return(zoneResult.Count > 0 ? Request.CreateResponse(HttpStatusCode.OK, zoneResult) : Request.CreateResponse(HttpStatusCode.BadRequest, "Data Not Available for request")); } catch (Exception ex) { NLogHelper.Nlogger_LogError.LogError(ex, this.GetType().FullName, Request.GetActionDescriptor().ActionName, Request.RequestUri.PathAndQuery); HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Server Error. Contact Admin. Error Date : " + DateTime.Now.ToString()); return(response); } }
public async Task <HttpResponseMessage> GetZoneListByCharBasis(ZoneSearchRequest RQ) { try { List <ZoneSearchResponse> zoneResult = new List <ZoneSearchResponse>(); if (RQ.PageSize == 0) { return(Request.CreateResponse(HttpStatusCode.BadRequest, "Page Size should be greater than Zero.")); } else if (RQ.PageNo == 0) { RQ.PageNo = 1; } _database = MongoDBHandler.mDatabase(); var collection = _database.GetCollection <ZoneMaster>("ZoneMaster"); FilterDefinition <ZoneMaster> filterForZone; filterForZone = Builders <ZoneMaster> .Filter.Empty; if (RQ.Zone_name.Length >= 3) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.Regex(b => b.Zone_Name, new BsonRegularExpression(new Regex(RQ.Zone_name.Trim(), RegexOptions.IgnoreCase))); } if (RQ.ZoneTypes.Any()) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.In(b => b.Zone_Type, RQ.ZoneTypes.Select(x => x.Zone_Type.Trim().ToUpper())); } if (RQ.Zone_SubType.Any()) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.In(b => b.Zone_SubType, RQ.Zone_SubType.Select(x => x.ZoneSub_Type.Trim().ToUpper())); } if (!string.IsNullOrWhiteSpace(RQ.SystemCountryCode)) { filterForZone = filterForZone & Builders <ZoneMaster> .Filter.Eq(b => b.TLGXCountryCode, RQ.SystemCountryCode.Trim().ToUpper()); } if (RQ.ZoneCities.Any()) { List <string> cities = RQ.ZoneCities.Select(x => x.Zone_City.Trim().ToUpper()).ToList(); filterForZone = filterForZone & Builders <ZoneMaster> .Filter.ElemMatch(x => x.Zone_CityMapping, x => cities.Contains(x.TLGXCityCode)); } var resultCount = await collection.Find(filterForZone).CountDocumentsAsync(); //TotalResultReturned int TotalSearchedZone = (int)resultCount; if (TotalSearchedZone > 0) { var result = await collection.Find(filterForZone).Project(x => new ZoneSearchResponse { ZoneCode = x.Zone_Code, ZoneName = x.Zone_Name, ZoneSubType = x.Zone_SubType, ZoneType = x.Zone_Type, ZoneLocationPoint = new ZoneGeoLocationResponse { Zone_Latitude = x.Latitude, Zone_Longitude = x.Longitude }, Zone_GeographyMapping = x.Zone_GeographyMapping }).Skip((RQ.PageNo - 1) * RQ.PageSize).Limit(RQ.PageSize).ToListAsync(); zoneResult = result; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, zoneResult); return(response); } else { HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, "Data Not Available for request"); return(response); } } catch (Exception ex) { NLogHelper.Nlogger_LogError.LogError(ex, this.GetType().FullName, Request.GetActionDescriptor().ActionName, Request.RequestUri.PathAndQuery); HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.InternalServerError, "Server Error. Contact Admin. Error Date : " + DateTime.Now.ToString()); return(response); } }