Пример #1
0
        public async Task <ActionResult <ElectionResponse> > GetBallot([FromQuery] ElectionResultsQuery query)
        {
            try
            {
                if (query.LocalityId == 0)
                {
                    query.LocalityId = null;
                }
                if (query.CountyId == 0)
                {
                    query.CountyId = null;
                }
                if (query.Round == 0)
                {
                    query.Round = null;
                }
                var result = await _resultsAggregator.GetBallotResults(query);

                return(result.Value);
            }
            catch (Exception e)
            {
                Log.LogError(e, "Exception encountered while retrieving voter turnout stats");
                return(StatusCode(500, e.Message));
            }
        }
Пример #2
0
        public async Task <ActionResult <ElectionResponse> > GetBallot([FromQuery] ElectionResultsQuery query)
        {
            try
            {
                if (query.LocalityId == 0)
                {
                    query.LocalityId = null;
                }
                if (query.CountyId == 0)
                {
                    query.CountyId = null;
                }
                if (query.Round == 0)
                {
                    query.Round = null;
                }

                var expiration = GetExpirationDate(query);
                var result     = await _appCache.GetOrAddAsync(
                    query.GetCacheKey(), () => _resultsAggregator.GetBallotResults(query),
                    expiration);

                var newsFeed = await _resultsAggregator.GetNewsFeed(query, result.Value.Meta.ElectionId);

                result.Value.ElectionNews = newsFeed;
                return(result.Value);
            }
            catch (Exception e)
            {
                _appCache.Remove(query.GetCacheKey());
                Log.LogError(e, "Exception encountered while retrieving voter turnout stats");
                return(StatusCode(500, e.StackTrace));
            }
        }