Example #1
0
        public static DemandingCriterias CreateFromCourse(GroupCourse course, ISerializationService serializationService)
        {
            var courseDates = course.GetAllCourseDates(serializationService).ToArray();

            return(new DemandingCriterias
            {
                CourseType = CourseType.Group,
                Discipline = course.Discipline,
                NiveauId = course.NiveauId,
                From = courseDates.First().Start.Date,
                To = courseDates.First().End.Date,
                IsCourse = true
            });
        }
Example #2
0
            private void SolveAndApplyGroupCourseComposition(GroupCourse proposalGroupCourse)
            {
                var solverParticipants = proposalGroupCourse.Participants.Select(p => new SolverParticipant(p.Participant, courseNiveauId: proposalGroupCourse.NiveauId)).ToArray();
                var solverResults      = Enumerable.Range(1, proposalGroupCourse.MaximalBoundedInstructorCount())
                                         .SelectMany(i => _solver.Solve(new SolverParam(i, solverParticipants)))
                                         .ToArray();

                var committedGroupCourseIds = new Guid[0];

                foreach (var efficientCourse in EfficientResult(solverResults).Courses)
                {
                    var participantIds = efficientCourse.Participants.Select(p => p.Id).ToArray();

                    var course = _courseCreationService.GetOrCreateGroupCourse(proposalGroupCourse, participantIds, committedGroupCourseIds);
                    course.ApplyParticipants(participantIds);
                    course.ApplyInstructor(() =>
                                           SelectInstructor(
                                               _demandService.GetAvailableInstructorsForGroupCourses(
                                                   proposalGroupCourse.Discipline, proposalGroupCourse.GetAllCourseDates(_serializationService).ToArray()
                                                   )
                                               )
                                           );

                    var isNew = course.RowVersion == null || course.RowVersion.Length == 0;

                    _unitOfWork.Commit();

                    if (isNew)
                    {
                        _queue.Publish(new CommittedCourseCreatedMessage(course.Instructor?.Id, course.Id));
                    }
                    else
                    {
                        _queue.Publish(new CommittedCourseChangedMessage(course.Instructor?.Id, course.Id));
                    }

                    committedGroupCourseIds = committedGroupCourseIds.Concat(new[] { course.Id }).ToArray();
                }

                if (_courseCreationService.RemoveUnusedButMatchingGroupCourses(proposalGroupCourse, committedGroupCourseIds))
                {
                    _unitOfWork.Commit();
                }
            }
Example #3
0
        public void GetAllCourseDates_ThreeWeekMondayFridayMorningCourse()
        {
            // Arrange
            var course = new GroupCourse(default(Discipline), default(CourseStatus), default(int), new DateTime(2018, 4, 30));

            course.SetPeriodsOptions(SerializationService, CreateOptions(ThreeWeekMondayFridayMorningCourse()));

            // Act
            var result = course.GetAllCourseDates(SerializationService).ToArray();

            // Assert
            var allStartTimes = result.Select(r => r.Start);

            CollectionAssert.AreEqual(
                new[]
            {
                new DateTime(2018, 4, 30, 8, 15, 0),
                new DateTime(2018, 5, 4, 8, 15, 0),
                new DateTime(2018, 5, 7, 8, 0, 0),
                new DateTime(2018, 5, 11, 8, 0, 0),
                new DateTime(2018, 5, 14, 7, 0, 0),
                new DateTime(2018, 5, 18, 7, 0, 0)
            },
                allStartTimes
                );

            var allEndTimes = result.Select(r => r.End);

            CollectionAssert.AreEqual(
                new[]
            {
                new DateTime(2018, 4, 30, 12, 0, 0),
                new DateTime(2018, 5, 4, 12, 0, 0),
                new DateTime(2018, 5, 7, 12, 0, 0),
                new DateTime(2018, 5, 11, 12, 0, 0),
                new DateTime(2018, 5, 14, 11, 0, 0),
                new DateTime(2018, 5, 18, 11, 0, 0)
            },
                allEndTimes
                );
        }
Example #4
0
 public ICollection <Period> Resolve(GroupCourse source, CourseDto destination, ICollection <Period> destMember, ResolutionContext context)
 {
     return(source.GetAllCourseDates((ISerializationService)context.Mapper.ServiceCtor(typeof(ISerializationService))).ToArray());
 }