Esempio n. 1
0
        public ActionResult Profile(int id)
        {
            var player         = _playersRepository.FindBy(c => c.Id == id).Single();
            var playerSessions = _playerService.GetSessions(id);
            var grouping       = playerSessions.GroupBy(c => c.Club.Name).OrderBy(c => c.Key).ToList();
            var vm             = Mapper.Map <PlayerProfileViewModel>(player);

            if (playerSessions.Any())
            {
                var all = Mapper.Map <PlayerSessionListViewModel>(playerSessions);
                all.Title = "Все игры";

                var groupingSessions = grouping.Select(g =>
                {
                    var tmp   = Mapper.Map <PlayerSessionListViewModel>(g.ToList());
                    tmp.Title = g.Key;

                    return(tmp);
                }).ToList();

                vm.Sessions.Add(all);
                vm.Sessions.AddRange(groupingSessions);
                vm.Visitation = new PlayerVisitation
                {
                    VisitationItems = grouping.Select(c => new PlayerVisitationItem()
                    {
                        ClubName = c.Key,
                        Persent  = ((int)((double)c.Count() / playerSessions.Count * 100)).ToString()
                    }).ToList()
                };
            }
            return(View(vm));
        }