Exemple #1
0
        static SearchController()
        {
            var picr = new PropertyIgnoreContractResolver();

            picr.IgnoreProperty(typeof(BaseEntity), "Id");
            picr.IgnoreProperty(typeof(UrlSearchResult), "UrlId", "SearchResultId", "SearchResult");
            picr.IgnoreProperty(typeof(UrlSearchResultSearchEngine), "UrlSearchResultId", "UrlSearchResult", "SearchEngineId");
            picr.IgnoreProperty(typeof(Url), "UrlSearchResults");

            _jsonSerializerSettings = new JsonSerializerSettings()
            {
                ContractResolver = picr,
            };
        }
Exemple #2
0
        public async Task <IActionResult> OnGet([FromQuery] bool raw = false)
        {
            var topics = (await _context.Topics.ToListAsync()).Where(topic => topic.ParentId == null);

            var jsonResolver = new PropertyIgnoreContractResolver();

            jsonResolver.Ignore <Topic>("Parent", "ParentId");

            var serializerSettings = new JsonSerializerSettings();

            serializerSettings.ContractResolver = jsonResolver;

            JsonTopics = JsonConvert.SerializeObject(topics, Formatting.Indented, serializerSettings);

            if (raw)
            {
                return(Content(JsonTopics));
            }
            else
            {
                return(Page());
            }
        }