Move query to utility class
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Specialized;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Caching;
|
using System.Web.Caching;
|
||||||
@@ -10,6 +9,7 @@ using LeafWeb.Core.Utility;
|
|||||||
using LeafWeb.WebCms.Models;
|
using LeafWeb.WebCms.Models;
|
||||||
using LeafWeb.WebCms.Services;
|
using LeafWeb.WebCms.Services;
|
||||||
using LeafWeb.WebCms.Services.PiscalQueue;
|
using LeafWeb.WebCms.Services.PiscalQueue;
|
||||||
|
using LeafWeb.WebCms.Utility;
|
||||||
using Umbraco.Web.Mvc;
|
using Umbraco.Web.Mvc;
|
||||||
|
|
||||||
namespace LeafWeb.WebCms.Controllers
|
namespace LeafWeb.WebCms.Controllers
|
||||||
@@ -21,26 +21,12 @@ namespace LeafWeb.WebCms.Controllers
|
|||||||
|
|
||||||
public ActionResult Index(LeafDataQuery query)
|
public ActionResult Index(LeafDataQuery query)
|
||||||
{
|
{
|
||||||
//query.lat = 32;
|
|
||||||
|
|
||||||
var resultItems =
|
var resultItems =
|
||||||
DataService.GetLeafInputsOrdered();
|
DataService.GetLeafInputsOrdered();
|
||||||
|
|
||||||
// search functionality
|
resultItems = QueryFilter.Search(resultItems, query);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var timeInProgressEstimater = TimeInProgressEstimater();
|
var timeInProgressEstimater = TimeInProgressEstimater();
|
||||||
|
|
||||||
var serviceDescription = ServiceDescription();
|
var serviceDescription = ServiceDescription();
|
||||||
|
|
||||||
|
|||||||
@@ -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<LeafInput> Search(IQueryable<LeafInput> 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1127,6 +1127,7 @@
|
|||||||
<Compile Include="Services\PiscalQueue\PiscalQueueWorker.cs" />
|
<Compile Include="Services\PiscalQueue\PiscalQueueWorker.cs" />
|
||||||
<Compile Include="Services\PiscalQueue\PiscalService.cs" />
|
<Compile Include="Services\PiscalQueue\PiscalService.cs" />
|
||||||
<Compile Include="Services\PiscalQueue\StartPending.cs" />
|
<Compile Include="Services\PiscalQueue\StartPending.cs" />
|
||||||
|
<Compile Include="Utility\QueryFilter.cs" />
|
||||||
<Compile Include="Utility\RequireRequestValueAttribute.cs" />
|
<Compile Include="Utility\RequireRequestValueAttribute.cs" />
|
||||||
<Compile Include="Utility\Validation.cs" />
|
<Compile Include="Utility\Validation.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user