示例#1
0
        public Lib.Data.Dotace.Dotace Detail(string id = null)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                throw new HttpResponseException(new ErrorMessage(System.Net.HttpStatusCode.BadRequest, $"Hodnota id chybí."));
            }

            var dotace = new Lib.Data.Dotace.DotaceService().Get(id);

            if (dotace == null)
            {
                throw new HttpResponseException(new ErrorMessage(System.Net.HttpStatusCode.NotFound, $"Dotace nenalezena"));
            }
            return(dotace);
        }
示例#2
0
        public SearchResultDTO <Lib.Data.Dotace.Dotace> Hledat([FromUri] string dotaz = null, [FromUri] int?strana = null, [FromUri] int?razeni = null)
        {
            if (strana < 1)
            {
                strana = 1;
            }
            if (strana * ApiV2Controller.DefaultResultPageSize > ApiV2Controller.MaxResultsFromES)
            {
                throw new HttpResponseException(new ErrorMessage(System.Net.HttpStatusCode.BadRequest, $"Hodnota 'strana' nemůže být větší než {ApiV2Controller.MaxResultsFromES / ApiV2Controller.DefaultResultPageSize}"));
            }

            Lib.Searching.DotaceSearchResult result = null;

            if (string.IsNullOrWhiteSpace(dotaz))
            {
                throw new HttpResponseException(new ErrorMessage(System.Net.HttpStatusCode.BadRequest, $"Hodnota dotaz chybí."));
            }


            result = new Lib.Data.Dotace.DotaceService().SimpleSearch(dotaz, strana.Value,
                                                                      ApiV2Controller.DefaultResultPageSize,
                                                                      (razeni ?? 0).ToString());

            if (result.IsValid == false)
            {
                throw new HttpResponseException(new ErrorMessage(System.Net.HttpStatusCode.BadRequest, $"Špatně nastavená hodnota dotaz=[{dotaz}]"));
            }
            else
            {
                var filtered = result.ElasticResults.Hits
                               .Select(m => m.Source)
                               .ToArray();

                return(new SearchResultDTO <Lib.Data.Dotace.Dotace>(result.Total, result.Page, filtered));
            }
        }