Beispiel #1
0
        public async Task <IEnumerable <ScheduledTrainingDto> > HandleAsync(CoachScheduleQuery query)
        {
            var groups = await _dbContext.TrainingGroups.Include(g => g.Coach).Include(g => g.PlayerTrainingGroups)
                         .Where(g => g.CoachId == query.CoachId)
                         .Select(g => new ScheduledTrainingDto()
            {
                GroupName = g.Name,
                CoachName = $"{g.Coach.Name} {g.Coach.Surname}",
                LevelName = g.LevelName,
                Day       = g.Day,
                Hour      = g.Hour.ToString(),
                Players   = g.PlayerTrainingGroups.Select(ptg => new PlayerDto()
                {
                    Id = ptg.PlayerId
                })
            })
                         .OrderBy(t => t.Day)
                         .ThenBy(t => t.Hour)
                         .ToListAsync();

            foreach (var group in groups)
            {
                var playerIds = group.Players.Select(g => g.Id).ToList();
                if (playerIds.Count == 0)
                {
                    group.Players = new List <PlayerDto>();
                }
                else
                {
                    var players = await _playersServiceClient.GetPlayers(playerIds);

                    group.Players = players.ToList().Select(p => new PlayerDto()
                    {
                        Name    = p.Name,
                        Surname = p.Surname,
                        Age     = p.Age,
                        LevelId = p.LevelId,
                        Points  = p.Points,
                        Id      = p.Id
                    });
                }
            }

            return(groups);
        }
Beispiel #2
0
        public async Task <ActionResult> GetCoachSchedule(string coachId)
        {
            var query = new CoachScheduleQuery()
            {
                CoachId = new Guid(coachId)
            };
            var results = await _queryDispatcher.QueryAsync <IEnumerable <ScheduledTrainingDto> >(query);

            if (results == null)
            {
                return(NotFound());
            }
            else
            {
                var upd = results.GroupBy(g => g.Day)
                          .Select(day => new ScheduleDto()
                {
                    Day       = day.Key.ToString(),
                    Trainings = day.ToList()
                })
                          .ToList();
                return(Ok(upd));
            }
        }