public WillQuery(IWillListService service)
        {
            Name = "Will";

            FieldAsync <WillType, Will>(
                "single",
                arguments: new QueryArguments(
                    new QueryArgument <IntGraphType> {
                Name = "id"
            }
                    ),
                resolve: context =>
            {
                try
                {
                    var currentUser = (ClaimsPrincipal)context.UserContext["claimsprincipal"];
                }
                catch (Exception e)
                {
                }


                //
                var id = context.GetArgument <int>("id");
                return(service.GetAsync(id));
            }
                );

            FieldAsync <WillResultType <WillType, Will>, Results <Will> >(
                "lincssearch",
                arguments: new QueryArguments(
                    new QueryArgument <StringGraphType> {
                Name = "query"
            },
                    new QueryArgument <IntGraphType> {
                Name = "limit"
            },
                    new QueryArgument <IntGraphType> {
                Name = "offset"
            },
                    new QueryArgument <StringGraphType> {
                Name = "sortColumn"
            },
                    new QueryArgument <StringGraphType> {
                Name = "sortOrder"
            },
                    new QueryArgument <IntGraphType> {
                Name = "yearStart"
            },
                    new QueryArgument <IntGraphType> {
                Name = "yearEnd"
            },
                    new QueryArgument <StringGraphType> {
                Name = "ref"
            },
                    new QueryArgument <StringGraphType> {
                Name = "desc"
            },
                    new QueryArgument <StringGraphType> {
                Name = "place"
            },
                    new QueryArgument <StringGraphType> {
                Name = "surname"
            }


                    ),
                resolve: context =>
            {
                ClaimsPrincipal currentUser = null;

                try
                {
                    currentUser = (ClaimsPrincipal)context.UserContext["claimsprincipal"];
                }
                catch (Exception e)
                {
                }

                var obj = new Dictionary <string, string>();

                var query  = context.GetArgument <string>("query");
                var limit  = context.GetArgument <int>("limit");
                var offset = context.GetArgument <int>("offset");

                var sortColumn = context.GetArgument <string>("sortColumn");
                var sortOrder  = context.GetArgument <string>("sortOrder");

                var yearStart = context.GetArgument <int>("yearStart");
                var yearEnd   = context.GetArgument <int>("yearEnd");

                var refArg  = context.GetArgument <string>("ref");
                var desc    = context.GetArgument <string>("desc");
                var place   = context.GetArgument <string>("place");
                var surname = context.GetArgument <string>("surname");


                var pobj = new WillSearchParamObj();

                pobj.User       = currentUser;
                pobj.Limit      = limit;
                pobj.Offset     = offset;
                pobj.SortColumn = sortColumn;
                pobj.SortOrder  = sortOrder;
                pobj.YearEnd    = yearEnd;
                pobj.YearStart  = yearStart;
                pobj.RefArg     = refArg;
                pobj.Desc       = desc;
                pobj.Place      = place;
                pobj.Surname    = surname;



                return(service.LincolnshireWillsList(pobj));
            }
                );

            FieldAsync <WillResultType <WillType, Will>, Results <Will> >(
                "norfolksearch",
                arguments: new QueryArguments(
                    new QueryArgument <StringGraphType> {
                Name = "query"
            },
                    new QueryArgument <IntGraphType> {
                Name = "limit"
            },
                    new QueryArgument <IntGraphType> {
                Name = "offset"
            },
                    new QueryArgument <StringGraphType> {
                Name = "sortColumn"
            },
                    new QueryArgument <StringGraphType> {
                Name = "sortOrder"
            },
                    new QueryArgument <IntGraphType> {
                Name = "yearStart"
            },
                    new QueryArgument <IntGraphType> {
                Name = "yearEnd"
            },
                    new QueryArgument <StringGraphType> {
                Name = "ref"
            },
                    new QueryArgument <StringGraphType> {
                Name = "desc"
            },
                    new QueryArgument <StringGraphType> {
                Name = "place"
            },
                    new QueryArgument <StringGraphType> {
                Name = "surname"
            }


                    ),
                resolve: context =>
            {
                ClaimsPrincipal currentUser = null;

                try
                {
                    currentUser = (ClaimsPrincipal)context.UserContext["claimsprincipal"];
                }
                catch (Exception e)
                {
                }

                var obj = new Dictionary <string, string>();

                var query  = context.GetArgument <string>("query");
                var limit  = context.GetArgument <int>("limit");
                var offset = context.GetArgument <int>("offset");

                var sortColumn = context.GetArgument <string>("sortColumn");
                var sortOrder  = context.GetArgument <string>("sortOrder");

                var yearStart = context.GetArgument <int>("yearStart");
                var yearEnd   = context.GetArgument <int>("yearEnd");

                var refArg  = context.GetArgument <string>("ref");
                var desc    = context.GetArgument <string>("desc");
                var place   = context.GetArgument <string>("place");
                var surname = context.GetArgument <string>("surname");


                var pobj = new WillSearchParamObj();

                pobj.User       = currentUser;
                pobj.Limit      = limit;
                pobj.Offset     = offset;
                pobj.SortColumn = sortColumn;
                pobj.SortOrder  = sortOrder;
                pobj.YearEnd    = yearEnd;
                pobj.YearStart  = yearStart;
                pobj.RefArg     = refArg;
                pobj.Desc       = desc;
                pobj.Place      = place;
                pobj.Surname    = surname;



                return(service.NorfolkWillsList(pobj));
            }
                );
        }
        public async Task <Results <Will> > NorfolkWillsList(WillSearchParamObj searchParams)
        {
            var _wills = new List <Will>();

            var results = new Results <Will>();

            int totalRecs = 0;

            try
            {
                var a = new AzureDBContext(_imsConfigHelper.MSGGenDB01);

                //searchParams.First

                Func <int, int, bool> validDates = (start, end) => {
                    if (start <= 0 && end <= 0)
                    {
                        return(false);
                    }
                    if (start > end)
                    {
                        return(false);
                    }

                    return(true);
                };

                var unpaged = a.NorfolkWills
                              .WhereIf(!string.IsNullOrEmpty(searchParams.Surname), w => w.Surname.ToLower().Contains(searchParams.Surname))
                              .WhereIf(!string.IsNullOrEmpty(searchParams.Desc), w => w.Description.ToLower().Contains(searchParams.Desc))
                              .WhereIf(!string.IsNullOrEmpty(searchParams.RefArg), w => w.Reference.ToLower().Contains(searchParams.RefArg))
                              .WhereIf(!string.IsNullOrEmpty(searchParams.Place), w => w.Place.ToLower().Contains(searchParams.Place))
                              .WhereIf(validDates(searchParams.YearStart, searchParams.YearEnd),
                                       w => w.Year >= searchParams.YearStart && w.Year <= searchParams.YearEnd)
                              .SortIf(searchParams.SortColumn, searchParams.SortOrder);

                totalRecs = unpaged.Count();

                foreach (var app in unpaged.Skip(searchParams.Offset).Take(searchParams.Limit))
                {
                    _wills.Add(new Will()
                    {
                        Id          = app.Id,
                        Aliases     = app.Aliases ?? "",
                        Collection  = app.Collection ?? "",
                        DateString  = app.DateString ?? "",
                        Description = app.Description ?? "",
                        FirstName   = app.FirstName ?? "",
                        Occupation  = app.Occupation ?? "",
                        Place       = app.Place ?? "",
                        Reference   = app.Reference ?? "",
                        Surname     = app.Surname ?? "",
                        Typ         = app.Typ.GetValueOrDefault(),
                        Url         = app.Url ?? "",
                        Year        = app.Year
                    });
                }
            }
            catch (Exception e)
            {
                results.Error = e.Message;
            }



            results.results       = _wills;
            results.Page          = searchParams.Offset == 0 ? 0 : searchParams.Offset / searchParams.Limit;
            results.total_pages   = totalRecs / searchParams.Limit;
            results.total_results = totalRecs;

            return(results);
        }