Exemplo n.º 1
0
        public async Task AddTeamSchedule(AddSchedule command)
        {
            await _administratorService.ValidateAtLeastModerator(command.UserId, command.GroupId);

            var group = await _groupRepository.GetWithTeamScheduleAndCourses(command.GroupId, command.TeamName);

            if (group == null)
            {
                throw new AppException($"Team with name {command.TeamName} doesn't exist.", AppErrorCode.DOESNT_EXIST);
            }

            var schedule = ScheduleFactory.Create(command.Schedule, group.Courses);
            var team     = group.Teams.First(t => t.Name == command.TeamName);

            team.AddSchedule(schedule);

            await _groupRepository.SaveChangesAsync();
        }
Exemplo n.º 2
0
        public async Task UpdateTeamSchedule(UpdateSchedule command)
        {
            await _administratorService.ValidateAtLeastModerator(command.UserId, command.GroupId);

            var group = await _groupRepository.GetWithTeamScheduleAndCourses(command.GroupId, command.TeamName);

            if (group == null)
            {
                throw new AppException($"Team with name {command.TeamName} doesn't exist.", AppErrorCode.DOESNT_EXIST);
            }

            var schedule         = ScheduleFactory.Create(command.Schedule, group.Courses);
            var scheduleToUpdate = group.Teams.First(t => t.Name == command.TeamName)
                                   .Schedules.FirstOrDefault(s => s.Semester == command.Schedule.Semester);

            if (scheduleToUpdate == null)
            {
                throw new AppException($"There is no schedule to update for semester {command.Schedule.Semester}", AppErrorCode.DOESNT_EXIST);
            }

            scheduleToUpdate.Update(schedule.Semester, schedule.ScheduledCourses);

            await _groupRepository.SaveChangesAsync();
        }