Esempio n. 1
0
        /// <summary>
        /// Get voters count for specific Event
        /// </summary>
        /// <param name="eventId">Event Id</param>
        /// <returns>Voters count</returns>
        public async Task <int> GetTotalNumberOfVotersForEvent(Guid eventId)
        {
            var places = await _eventDetailsService.GetPlacesWithVotes(eventId);

            var timeSlots = await _eventDetailsService.GetDatesWithVotes(eventId);

            var placesTotalVoters = places.Where(p => p.VotesForPlace != null).SelectMany(p => p.VotesForPlace?.Select(v => v.UserId).ToList()).Distinct();
            var datesTotalVoters  = timeSlots.Where(p => p.VotesForDate != null).SelectMany(p => p.VotesForDate?.Select(v => v.UserId).ToList()).Distinct();

            return(placesTotalVoters.Union(datesTotalVoters).Distinct().Count());
        }
Esempio n. 2
0
        public async Task <JsonResult> GetVoteForPlaceModel(Guid eventId)
        {
            var totalNumberOfVoters = await _votingService.GetTotalNumberOfVotersForEvent(eventId);

            var places = await _eventDetailsService.GetPlacesWithVotes(eventId);

            var placesVm = places.Select(Mapper.Map <PlaceViewModel>).ToList();
            await _placeService.PopulateVenueDetailsAsync(placesVm);

            var optionsVm = placesVm
                            .OrderBy(pl => pl.VotesForPlace.Count(v => v.WillAttend == WillAttend.Yes))
                            .Select((pl) => MappingHelper.MapToOptionViewModel(pl, User.Identity.GetUserId()))
                            .ToList();

            return(Json(new { Options = optionsVm, TotalNumberOfVoters = totalNumberOfVoters },
                        JsonRequestBehavior.AllowGet));
        }