Ejemplo n.º 1
0
        public IActionResult GetStats(CancellationToken cancellationToken)
        {
            var stats  = new Stats();
            var events = eventRepository.GetEvents(cancellationToken);

            stats.TotalEvents = events.Count();

            var eventSummaries = eventSummaryRepository.GetEventSummaries(cancellationToken);

            stats.TotalBags         = eventSummaries.Sum(es => es.NumberOfBags) + (eventSummaries.Sum(es => es.NumberOfBuckets) / 3);
            stats.TotalHours        = eventSummaries.Sum(es => es.DurationInMinutes * es.ActualNumberOfAttendees / 60);
            stats.TotalParticipants = eventSummaries.Sum(es => es.ActualNumberOfAttendees);

            return(Ok(stats));
        }
        public async Task <IActionResult> GetEventSummaries([FromQuery] string country = "", [FromQuery] string region = "", [FromQuery] string city = "", [FromQuery] string postalCode = "", CancellationToken cancellationToken = default)
        {
            // Todo make this more efficient
            var eventSummaries   = eventSummaryRepository.GetEventSummaries(cancellationToken).ToList();
            var displaySummaries = new List <DisplayEventSummary>();

            foreach (var eventSummary in eventSummaries)
            {
                var mobEvent = await eventRepository.GetEvent(eventSummary.EventId, cancellationToken).ConfigureAwait(false);

                if (mobEvent != null)
                {
                    if ((string.IsNullOrWhiteSpace(country) || string.Equals(mobEvent.Country, country, StringComparison.OrdinalIgnoreCase)) &&
                        (string.IsNullOrWhiteSpace(region) || string.Equals(mobEvent.Region, region, StringComparison.OrdinalIgnoreCase)) &&
                        (string.IsNullOrWhiteSpace(city) || mobEvent.City.Contains(city, StringComparison.OrdinalIgnoreCase)) &&
                        (string.IsNullOrWhiteSpace(postalCode) || mobEvent.PostalCode.Contains(postalCode, StringComparison.OrdinalIgnoreCase)))
                    {
                        var displayEvent = new DisplayEventSummary()
                        {
                            ActualNumberOfAttendees = eventSummary.ActualNumberOfAttendees,
                            City              = mobEvent.City,
                            Country           = mobEvent.Country,
                            DurationInMinutes = eventSummary.DurationInMinutes,
                            EventDate         = mobEvent.EventDate,
                            EventId           = mobEvent.Id,
                            EventTypeId       = mobEvent.EventTypeId,
                            Name              = mobEvent.Name,
                            NumberOfBags      = eventSummary.NumberOfBags + eventSummary.NumberOfBuckets / 3.0,
                            PostalCode        = mobEvent.PostalCode,
                            Region            = mobEvent.Region,
                            StreetAddress     = mobEvent.StreetAddress,
                            TotalWorkHours    = eventSummary.ActualNumberOfAttendees * eventSummary.DurationInMinutes / 60.0
                        };

                        displaySummaries.Add(displayEvent);
                    }
                }
            }

            return(Ok(displaySummaries));
        }