Esempio n. 1
0
        public IEnumerable<ParticipantLeaderViewModel> GetSortedUsersForUnit(int unit)
        {
            ActivityDataService dataService = new ActivityDataService();

            // first get all acitivty data matching the unit
            var activityData = dataService.GetAllActivityData();
            activityData = activityData.Where(a => a.categoryunit.unit.Id == unit);

            // group activity data by user
            // then for each group calculate the total and store it in a model
            var transformedUsers = activityData
                            .Where(a => a.User.Id != null) // ignore data that does not have a user
                            .GroupBy(a => a.User.Id)
                            .ToList()
                            .Select(g => new ParticipantLeaderViewModel
                            {
                                User = db.Users.Find(g.Key),
                                Total = g.Sum(x => x.value).GetValueOrDefault(0)
                            });

            // finally order the views according to who is the best
            return transformedUsers.OrderByDescending(m => m.Total);
        }
Esempio n. 2
0
        public IEnumerable<LeaderViewModel> GetSortedGroupsForUnit(int unit)
        {
            ActivityDataService dataService = new ActivityDataService();

            // first get all acitivty data matching the unit
            var activityData = dataService.GetAllActivityData();
            activityData = activityData.Where(a => a.categoryunit.unit.Id == unit);

            // group activity data by Group
            // then for each group calculate the total and store it in a model
            var transformedGroups = activityData
                            .Where(a => a.User.TeamId != null) // ignore people who are not in a team
                            .GroupBy(a => a.User.TeamId)
                            .ToList()
                            .Select(g => new LeaderViewModel
                            {
                                Name = db.Teams.Find(g.Key).name,
                                NumMembers = g.Count(),
                                Total = g.Sum(x => x.value).GetValueOrDefault(0)
                            });

            return transformedGroups.OrderByDescending(m => m.Total);
        }
Esempio n. 3
0
        public IEnumerable<LeaderViewModel> getGroupChallengeLeaders(Challenge challenge)
        {
            ActivityDataService dataService = new ActivityDataService();

            // first get all acitivty data matching the unit
            var activityData = dataService.GetAllActivityData()
                                .Where(a => a.categoryunit.unit.Id == challenge.categoryUnit.unit.Id)
                                .ToList();

            var data = activityData.Where(a => challenge.userchallenges.Any(x => x.User.Id.Equals(a.User.Id)));

            IEnumerable <LeaderViewModel> model = challenge.groupchallenges.Select(c => new LeaderViewModel
            {
                Name = c.group.name,
                Total = data.Where(a => a.User.TeamId == c.group.Id).Sum(a => a.value).GetValueOrDefault(),
                NumMembers = data.Where(a => a.User.TeamId == c.group.Id).GroupBy(a => a.User.Id).Count()
            });

            return model.OrderByDescending(m => m.Total);
        }