using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System; using System.Linq; using System.Linq.Expressions; namespace zero.Core.Entities { public class ListBackofficeQuery : ListQuery { public ListBackofficeQuery() { IncludeInactive = true; } } public class ListBackofficeQuery : ListQuery where TFilter : IListSpecificQuery { public ListBackofficeQuery() { IncludeInactive = true; } } public class ListQuery { public string Search { get; set; } = null; public Expression> SearchSelector { get; set; } = null; public Expression>[] SearchSelectors { get; private set; } = new Expression>[0] { }; public string OrderBy { get; set; } = "createdDate"; public ListQueryOrderType OrderType { get; set; } = ListQueryOrderType.String; public bool OrderIsDescending { get; set; } = true; public Func, IQueryable> OrderQuery = null; public int Page { get; set; } = 1; public int PageSize { get; set; } = 30; public bool IncludeInactive { get; set; } = false; public void SearchFor(params Expression>[] selectors) { SearchSelectors = selectors; } } public class ListQuery : ListQuery where TFilter : IListSpecificQuery { public TFilter Filter { get; set; } } public static class ListQueryExtensions { public static ListQuery AsList(this string options) where TFilter : IListSpecificQuery { return JsonConvert.DeserializeObject>(options); } public static ListQuery AsList(this string options) where T : IListSpecificQuery { return JsonConvert.DeserializeObject>(options); } } public interface IListSpecificQuery { } public class EmptyListSpecificQuery : IListSpecificQuery { } public class ListQueryDateRange { public DateTimeOffset? From { get; set; } public DateTimeOffset? To { get; set; } } public class ListQueryRange { public decimal? From { get; set; } public decimal? To { get; set; } } public enum ListQueryOrderType { String, Number } }