79 lines
2.5 KiB
C#
79 lines
2.5 KiB
C#
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;
|
|
}
|
|
}
|
|
} |