public void TestCreateLocationRadiusSearch() { const string propertyName = "query"; const string equalityValue = "42.14,54.22,43.14"; var filter = new LocationSearchFilter(propertyName, 42.14m, 54.22m, 43.14m); Assert.AreEqual(propertyName, filter.Field); Assert.AreEqual(equalityValue, filter.Value); Assert.AreEqual(SearchFilterComparer.LocationWithin.ToString(), filter.Comparison); }
public PaginatedList <Location> GetAllPaginatedWithDetailBySearchFilter(LocationSearchFilter searchFilter) { PaginatedList <Location> resultList = new PaginatedList <Location>(new List <Location>(), 0, searchFilter.CurrentPage, searchFilter.PageSize, searchFilter.SortOn, searchFilter.SortDirection); using (AppDBContext dbContext = new AppDBContext(_config)) { var query = from a in dbContext.Location select a; // filtering if (!string.IsNullOrEmpty(searchFilter.Filter_Name)) { query = query.Where(r => r.Name.Contains(searchFilter.Filter_Name)); } // asnotracking query = query.AsNoTracking(); //total count var totalCount = query.Count(); //sorting if (!string.IsNullOrEmpty(searchFilter.SortOn)) { // using System.Linq.Dynamic.Core; nuget paketi ve namespace eklenmelidir, dynamic order by yapmak icindir query = query.OrderBy(searchFilter.SortOn + " " + searchFilter.SortDirection.ToUpper()); } else { // deefault sıralama vermek gerekiyor yoksa skip metodu hata veriyor ef 6'da -- 28.10.2019 15:40 // https://stackoverflow.com/questions/3437178/the-method-skip-is-only-supported-for-sorted-input-in-linq-to-entities query = query.OrderBy(r => r.Id); } //paging query = query.Skip((searchFilter.CurrentPage - 1) * searchFilter.PageSize).Take(searchFilter.PageSize); resultList = new PaginatedList <Location>( query.ToList(), totalCount, searchFilter.CurrentPage, searchFilter.PageSize, searchFilter.SortOn, searchFilter.SortDirection ); } return(resultList); }
public IActionResult GetAllPaginatedWithDetail([FromQuery] GetAllPaginatedRequestModel requestModel, [FromHeader] string displayLanguage) { var responseModel = new Return <PaginatedList <Location> >(); responseModel.DisplayLanguage = displayLanguage; try { var searchFilter = new LocationSearchFilter(); searchFilter.CurrentPage = requestModel.CurrentPage.HasValue ? requestModel.CurrentPage.Value : 1; searchFilter.PageSize = requestModel.PageSize.HasValue ? requestModel.PageSize.Value : 10; searchFilter.SortOn = requestModel.SortOn; searchFilter.SortDirection = requestModel.SortDirection; searchFilter.Filter_Name = requestModel.Name; responseModel.Data = _locationService.GetAllPaginatedWithDetailBySearchFilter(searchFilter); responseModel.Status = ResultStatusCodeStatic.Success; responseModel.Message = "Success"; responseModel.Success = true; return(Ok(responseModel)); } catch (Exception ex) { responseModel.Status = ResultStatusCodeStatic.InternalServerError; responseModel.Message = "An error occurred"; responseModel.Success = false; ReturnError error = new ReturnError(); error.Key = "500"; error.Message = ex.Message; error.Code = 500; responseModel.Errors = new List <ReturnError>(); responseModel.Errors.Add(error); responseModel.Data = null; //hata oluştugundan dolayı Data null olarak dönülür. return(StatusCode(StatusCodes.Status500InternalServerError, responseModel)); } }