internal PlaceSearchModel ToPlaceSearchModel() { PlaceSearchModel placeSearchModel = new PlaceSearchModel(); int?page = base.Page; placeSearchModel.Page = (page.HasValue ? page.GetValueOrDefault() : 1); page = base.PageSize; placeSearchModel.PageSize = (page.HasValue ? page.GetValueOrDefault() : 20); placeSearchModel.SearchText = base.SearchText; placeSearchModel.Latitude = this.Latitude; placeSearchModel.Longitude = this.Longitude; return(placeSearchModel); }
/// <summary> /// Searches google for places by name /// </summary> public ActionResult Search(PlaceSearchModel search) { var model = InitModel(); search = search ?? new PlaceSearchModel(); model.SearchCriteria = search; model.SearchResults = new List <CartoPlaceInfo>(); if (!String.IsNullOrWhiteSpace(search.Location)) { model.SearchResults = _cartoPlaceService.LookupLocations(search.Location.Trim()); } else if (!String.IsNullOrWhiteSpace(search.Name)) { model.SearchResults = _cartoPlaceService.LookupPlaces(search.Name, search.Country); } else if (search.Latitude.HasValue && search.Longitude.HasValue) { var position = new GeoPosition(search.Latitude.Value, search.Longitude.Value); model.SearchResults = _cartoPlaceService.LookupLocations(position); } return(View(model)); }
public async Task <Result <List <PlaceDTO> > > GetAllPlaceAsync(PlaceSearchModel searchModel) { searchModel.FixPageDefinations(); ////int? companyId = searchModel.CompanyId; ////&& ((object)companyId == null || (object)(int?)w.CompanyId == (object)companyId) //IQueryable<Place> source = _unitOfWork.EntityRepository<Place>().GetQueryable((Place w) => w.IsDeleted == false, null); int?companyId = searchModel.CompanyId; IQueryable <Place> source = _unitOfWork.EntityRepository <Place>().GetQueryable((Place w) => w.IsDeleted == false && ((object)companyId == null || (object)(int?)w.CompanyId == (object)companyId), null); if (!string.IsNullOrEmpty(searchModel.SearchText)) { string[] searchTexts = searchModel.SearchText.ToLower().Split(' '); if (searchTexts.Length == 1) { source = from w in source where w.Name.ToLower().Contains(searchTexts[0].Trim()) select w; } if (searchTexts.Length > 1) { source = from w in source where searchTexts.Any((string x) => w.Name.ToLower().Trim().Contains(x)) select w; } } if (searchModel.Longitude.HasValue && searchModel.Latitude.HasValue) { XYPoint sourcePoint = new XYPoint(searchModel.Latitude.Value, searchModel.Longitude.Value); source = from w in source where w.Location != null select w into o orderby o.Location.Distance(sourcePoint) select o; } else { source = from o in source orderby o.Name select o; } var sorgu = source.ToString(); var temp = Result.Data(await EntityFrameworkQueryableExtensions.ToListAsync <PlaceDTO>(from s in source.Skip(searchModel.PageSize * searchModel.PageIndex).Take(searchModel.PageSize) select new PlaceDTO { Id = s.Id, Name = s.Name, Address = s.Address, Latitude = s.Latitude, Guest = s.Guest, Longitude = s.Longitude, CompanyId = s.CompanyId, Company = new CompanyInfoDTO { Id = s.Company.Id, Name = s.Company.Name, Image = s.Company.Image, Demo = s.Company.Demo } }, default(CancellationToken))); return(temp); }