public async Task <ActionResult> Index() { SelectList places = GetVotePlacesForSelect("Region"); SelectList targets = new SelectList(_targetModelService.GetTargetModels(), "Id", "Name"); ViewBag.Places = places; ViewBag.Targets = targets; var voteForm = new VoteForm(); if (HttpContext.User.Identity.IsAuthenticated) { ApplicationUser user = await _userManager.GetUserAsync(User); voteForm.PhoneNumber = user.PhoneNumber; } return(View(voteForm)); }
public ActionResult Targets() { var targets = _targetModelService.GetTargetModels(); return(View(targets.ToList())); }
public async Task <VoteStat> GetVoteStat() { //SELECT Target.Name, Count(Vote.Target) as "Total" //FROM Target LEFT JOIN Vote ON Vote.Target = Target.Id //GROUP BY Vote.Target, Target.Name; var votes = _voteModelService.GetVoteModels(); var targets = _targetModelService.GetTargetModels(); var voteStat_raw = (from T in targets join V in votes on T.Id equals V.TargetId.Id group T by new { T.Name, T.Id } into total select new { total.Key.Name, Count = total.Count() }); var totalVotes = votes.Count(); //SELECT Target.Name, COUNT(Target.Name) as "Total", VotePlace.Region //FROM Target //LEFT JOIN Vote ON Vote.Target = Target.Id //LEFT JOIN VotePlace ON VotePlace.Id = Vote.VotePlace //GROUP BY VotePlace.Region, Target.Name var votePlaces = _votePlaceModelService.GetVotePlaceModels(); var voteStatRegion_raw = (from T in targets join V in votes on T.Id equals V.TargetId.Id join VP in votePlaces on V.VotePlaceId.Id equals VP.Id group new { T, VP } by new { T.Name, VP.Region } into total select new { total.Key.Name, total.Key.Region, Total = total.Count() }); var voteStatRegion = voteStatRegion_raw.ToList(); var regions = (from VP in votePlaces group VP by new { VP.Id, VP.Region } into region select new { region.Key.Id, region.Key.Region }).Select(region => region.Region).ToList(); var targetsNames = (from T in targets group T by new { T.Id, T.Name } into target select new { target.Key.Id, target.Key.Name }).Select(target => target.Name).ToList(); VoteStat voteStat = new VoteStat() { VoteStats = new List <VotePropsForChart>(), VoteStatsRegion = new VotePropsForChartRegion() { regions = regions, targets = targetsNames }, Total = totalVotes }; voteStat.VoteStatsRegion.regionStates = new Dictionary <string, Dictionary <string, int> >(); foreach (var region in regions) { voteStat.VoteStatsRegion.regionStates.TryAdd(region, new Dictionary <string, int>()); } foreach (var stat in voteStatRegion) { voteStat.VoteStatsRegion.regionStates[stat.Region].Add(stat.Name, stat.Total); } var voteStat_pre = await voteStat_raw.ToListAsync(); foreach (var vote in voteStat_pre) { voteStat.VoteStats.Add( new VotePropsForChart { v = vote.Count, f = Convert.ToString(vote.Count), targetName = vote.Name }); } return(voteStat); }