Files
LeafWeb/WebCms/Models/LeafDataQuery.cs
T
poprhythm 2b5de1c4cd Replace WebGridBootstrapPager
Improve Leaf details page
2020-06-28 17:37:06 -04:00

82 lines
3.0 KiB
C#

using System.Collections.Specialized;
using System.ComponentModel.DataAnnotations;
using System.Runtime.CompilerServices;
namespace LeafWeb.WebCms.Models
{
public class LeafDataQuery
{
/// <summary>Query</summary>
[Display(Name = "Search", Description = "General query")]
public string q { get; set; }
[Display(Name = "Site ID", Description = "The site's name/Fluxnet ID, if known")]
[RegularExpression(@".{3,}", ErrorMessage = "Specify at least three characters")]
public string siteid { get; set; }
[Display(Name = "Species Name")]
[RegularExpression(@".{3,}", ErrorMessage = "Specify at least three characters")]
public string species { get; set; }
/// <summary>Site latitude, northern hemisphere positive</summary>
[Display(Name = "Latitude")]
[RegularExpression(@"^-?([0-9]|[1-8][0-9]|90)$", ErrorMessage = "Site latitude, northern hemisphere positive, -90 &ndash; 90")]
public string lat { get; set; }
[Display(Name = "Range")]
[RegularExpression(@"^([0-9]|[1-8][0-9]|90)$", ErrorMessage = "&plusmn; latitude degrees")]
public string latr { get; set; }
/// <summary>Site longitude, east positive</summary>
[Display(Name = "Longitude")]
[RegularExpression(@"^-?([0-9]|[1-8][0-9]|9[0-9]|1[0-7][0-9]|180)$", ErrorMessage = "Site longitude, east positive, -180 &ndash; 180")]
public string lon { get; set; }
[Display(Name = "Range")]
[RegularExpression(@"^([0-9]|[1-8][0-9]|9[0-9]|1[0-7][0-9]|180)$", ErrorMessage = "&plusmn; longitude degrees")]
public string lonr { get; set; }
static LeafDataQuery()
{
//Mapper.CreateMap<LeafInputCreate, LeafInput>()
// .ForMember(dest => dest.PhotosynthesisType, opt => opt.Ignore());
//Mapper.CreateMap<LeafInput, LeafInputCreate>()
// .ForMember(dest => dest.PhotosynthesisType, opt => opt.Ignore());
}
public LeafDataQuery()
{
//PhotosynthesisType = new SelectListViewModel();
}
public NameValueCollection GetNameValueCollection(string prefix="")
{
var nvs = new NameValueCollection();
prefix =
string.IsNullOrEmpty(prefix)
? ""
: prefix + ".";
foreach (var pi in typeof(LeafDataQuery).GetProperties())
{
var value = pi.GetValue(this, null);
if (value == null)
continue;
nvs.Add(prefix + pi.Name, value?.ToString());
}
return nvs;
}
public bool HasExtendedParameters =>
!(
string.IsNullOrEmpty(siteid)
&& string.IsNullOrEmpty(species)
&& string.IsNullOrEmpty(lat)
&& string.IsNullOrEmpty(latr)
&& string.IsNullOrEmpty(lon)
&& string.IsNullOrEmpty(lonr)
);
}
}