diff --git a/WebCms/Controllers/QueueController.cs b/WebCms/Controllers/QueueController.cs index 032e05a..c0347cd 100644 --- a/WebCms/Controllers/QueueController.cs +++ b/WebCms/Controllers/QueueController.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Specialized; using System.Linq; using System.Web; using System.Web.Caching; @@ -10,6 +9,7 @@ using LeafWeb.Core.Utility; using LeafWeb.WebCms.Models; using LeafWeb.WebCms.Services; using LeafWeb.WebCms.Services.PiscalQueue; +using LeafWeb.WebCms.Utility; using Umbraco.Web.Mvc; namespace LeafWeb.WebCms.Controllers @@ -21,26 +21,12 @@ namespace LeafWeb.WebCms.Controllers public ActionResult Index(LeafDataQuery query) { - //query.lat = 32; - var resultItems = DataService.GetLeafInputsOrdered(); - // search functionality - if (!string.IsNullOrEmpty(query.q)) - { - foreach (var piece in query.q.Split(' ').Select(p => p.Trim())) - { - resultItems = - from li in resultItems - where li.Name.Contains(piece) - || li.Identifier.Contains(piece) - || li.SiteId.Contains(piece) - select li; - } - } + resultItems = QueryFilter.Search(resultItems, query); - var timeInProgressEstimater = TimeInProgressEstimater(); + var timeInProgressEstimater = TimeInProgressEstimater(); var serviceDescription = ServiceDescription(); diff --git a/WebCms/Utility/QueryFilter.cs b/WebCms/Utility/QueryFilter.cs new file mode 100644 index 0000000..4dabbf0 --- /dev/null +++ b/WebCms/Utility/QueryFilter.cs @@ -0,0 +1,79 @@ +using System; +using System.Linq; +using LeafWeb.Core.Entities; +using LeafWeb.WebCms.Models; + +namespace LeafWeb.WebCms.Utility +{ + internal static class QueryFilter + { + public static IQueryable Search(IQueryable resultItems, LeafDataQuery query) + { + // search functionality + if (!string.IsNullOrEmpty(query.q)) + { + foreach (var piece in query.q.Split(' ').Select(p => p.Trim())) + { + resultItems = + from li in resultItems + where li.Name.Contains(piece) + || li.Identifier.Contains(piece) + || li.SiteId.Contains(piece) + select li; + } + } + + if (!string.IsNullOrEmpty(query.species)) + { + resultItems = + from li in resultItems + where li.LeafInputData.Any(lid => lid.MajorSpecies.Contains(query.species)) + select li; + } + + if (!string.IsNullOrEmpty(query.siteid)) + { + resultItems = + from li in resultItems + where li.SiteId.Contains(query.siteid) + select li; + } + + if (!string.IsNullOrEmpty(query.lat)) + { + var latitude = int.Parse(query.lat); + var range = 0; + if (!string.IsNullOrEmpty(query.latr)) + { + range = int.Parse(query.latr); + } + + resultItems = + from li in resultItems + where li.LeafInputData.Any(lid => + lid.Site.Latitude >= latitude - range && + lid.Site.Latitude <= latitude + range) + select li; + } + + if (!string.IsNullOrEmpty(query.lon)) + { + var longitude = Int32.Parse(query.lon); + var range = 0; + if (!string.IsNullOrEmpty(query.lonr)) + { + range = int.Parse(query.lonr); + } + + resultItems = + from li in resultItems + where li.LeafInputData.Any(lid => + lid.Site.Longitude >= longitude - range && + lid.Site.Longitude <= longitude + range) + select li; + } + + return resultItems; + } + } +} \ No newline at end of file diff --git a/WebCms/WebCms.csproj b/WebCms/WebCms.csproj index e86e2b0..7f9787c 100644 --- a/WebCms/WebCms.csproj +++ b/WebCms/WebCms.csproj @@ -1127,6 +1127,7 @@ +