예제 #1
0
        public ValidationErrorList GetCurriculumValidation(Curriculum curriculum) {
            var errors = new ValidationErrorList {Errors = new List<ValidationError>(), ErrorsText = new List<string>()};
            
            if (this.Storage.GetGroup(curriculum.UserGroupRef) == null) {
                errors.ErrorsText.Add(Localization.GetMessage("ChooseGroup"));
                errors.Errors.Add(new ValidationError { Type = ValidationErrorType.Group});
            }

            if (!this.Storage.GetDiscipline(curriculum.DisciplineRef).IsValid) {
                errors.ErrorsText.Add(Localization.GetMessage("DisciplineIsInvalid"));
                errors.Errors.Add(new ValidationError { Type = ValidationErrorType.Discipline});
            }

            var curriculumChapters = this.Storage.GetCurriculumChapters(item => item.CurriculumRef == curriculum.Id);
            
            foreach (var curriculumChapter in curriculumChapters)
            {
                if (curriculumChapter.StartDate < curriculum.StartDate || curriculumChapter.EndDate > curriculum.EndDate)
                {
                    errors.ErrorsText.Add(Localization.GetMessage("ChapterTimelineOut") + " - " + curriculumChapter.Chapter.Name);
                    errors.Errors.Add(new ValidationError {
                       Type = ValidationErrorType.ChapterTimeline,
                       ErrorData = new {
                          CurriculumChapterId = curriculumChapter.Id,
                          StartDateErr = curriculumChapter.StartDate < curriculum.StartDate,
                          EndDateErr = curriculumChapter.EndDate > curriculum.EndDate
                      }
                   });
                }
            
                var curriculumChapterTopics = this.Storage.GetCurriculumChapterTopics(item => item.CurriculumChapterRef == curriculumChapter.Id);
            
                foreach (var curriculumChapterTopic in curriculumChapterTopics)
                {
            
                    if (curriculumChapter.StartDate > curriculumChapterTopic.TestStartDate
                        || curriculumChapter.StartDate > curriculumChapterTopic.TheoryStartDate
                        || curriculumChapter.EndDate < curriculumChapterTopic.TheoryEndDate
                        || curriculumChapter.EndDate < curriculumChapterTopic.TestEndDate)
                    {
                        errors.ErrorsText.Add(Localization.GetMessage("TopicTimelineOut") + " - " + curriculumChapterTopic.Topic.Name);
                        errors.Errors.Add(new ValidationError {
                           Type = ValidationErrorType.TopicTimelineOutOfChapter,
                           ErrorData = new {
                              CurriculumChapterId = curriculumChapter.Id,
                              CurriculumChapterTopicId = curriculumChapterTopic.Id,
                              StartDateErr = curriculumChapter.StartDate > curriculumChapterTopic.TestStartDate
                                             || curriculumChapter.StartDate > curriculumChapterTopic.TheoryStartDate,
                              EndDateErr = curriculumChapter.EndDate < curriculumChapterTopic.TheoryEndDate
                                             || curriculumChapter.EndDate < curriculumChapterTopic.TestEndDate
                          }
                       });
                    }
                    else if (curriculum.StartDate > curriculumChapterTopic.TestStartDate
                        || curriculum.StartDate > curriculumChapterTopic.TheoryStartDate
                        || curriculum.EndDate < curriculumChapterTopic.TheoryEndDate
                        || curriculum.EndDate < curriculumChapterTopic.TestEndDate)
                    {
                        errors.ErrorsText.Add(Localization.GetMessage("TopicTimelineOutOfCurriculum") + " - " + curriculumChapterTopic.Topic.Name);
                        errors.Errors.Add(new ValidationError {
                           Type = ValidationErrorType.TopicTimelineOutOfCurriculum,
                           ErrorData = new {
                              CurriculumChapterId = curriculumChapter.Id,
                              CurriculumChapterTopicId = curriculumChapterTopic.Id,
                              StartDateErr = curriculum.StartDate > curriculumChapterTopic.TestStartDate
                                             || curriculum.StartDate > curriculumChapterTopic.TheoryStartDate,
                              EndDateErr = curriculum.EndDate < curriculumChapterTopic.TheoryEndDate
                                             || curriculum.EndDate < curriculumChapterTopic.TestEndDate
                           }
                        });
                    }
                }
            }

            return errors;
        }
예제 #2
0
        public ValidationErrorList GetCurriculumValidation(Curriculum curriculum)
        {
            var errors = new ValidationErrorList {
                Errors = new List <ValidationError>(), ErrorsText = new List <string>()
            };

            if (this.Storage.GetGroup(curriculum.UserGroupRef) == null)
            {
                errors.ErrorsText.Add(Localization.GetMessage("ChooseGroup"));
                errors.Errors.Add(new ValidationError {
                    Type = ValidationErrorType.Group
                });
            }

            if (!this.Storage.GetDiscipline(curriculum.DisciplineRef).IsValid)
            {
                errors.ErrorsText.Add(Localization.GetMessage("DisciplineIsInvalid"));
                errors.Errors.Add(new ValidationError {
                    Type = ValidationErrorType.Discipline
                });
            }

            var curriculumChapters = this.Storage.GetCurriculumChapters(item => item.CurriculumRef == curriculum.Id);

            foreach (var curriculumChapter in curriculumChapters)
            {
                if (curriculumChapter.StartDate < curriculum.StartDate || curriculumChapter.EndDate > curriculum.EndDate)
                {
                    errors.ErrorsText.Add(Localization.GetMessage("ChapterTimelineOut") + " - " + curriculumChapter.Chapter.Name);
                    errors.Errors.Add(new ValidationError {
                        Type      = ValidationErrorType.ChapterTimeline,
                        ErrorData = new {
                            CurriculumChapterId = curriculumChapter.Id,
                            StartDateErr        = curriculumChapter.StartDate <curriculum.StartDate,
                                                                               EndDateErr = curriculumChapter.EndDate> curriculum.EndDate
                        }
                    });
                }

                var curriculumChapterTopics = this.Storage.GetCurriculumChapterTopics(item => item.CurriculumChapterRef == curriculumChapter.Id);

                foreach (var curriculumChapterTopic in curriculumChapterTopics)
                {
                    if (curriculumChapter.StartDate > curriculumChapterTopic.TestStartDate ||
                        curriculumChapter.StartDate > curriculumChapterTopic.TheoryStartDate ||
                        curriculumChapter.EndDate < curriculumChapterTopic.TheoryEndDate ||
                        curriculumChapter.EndDate < curriculumChapterTopic.TestEndDate)
                    {
                        errors.ErrorsText.Add(Localization.GetMessage("TopicTimelineOut") + " - " + curriculumChapterTopic.Topic.Name);
                        errors.Errors.Add(new ValidationError {
                            Type      = ValidationErrorType.TopicTimelineOutOfChapter,
                            ErrorData = new {
                                CurriculumChapterId      = curriculumChapter.Id,
                                CurriculumChapterTopicId = curriculumChapterTopic.Id,
                                StartDateErr             = curriculumChapter.StartDate > curriculumChapterTopic.TestStartDate ||
                                                           curriculumChapter.StartDate > curriculumChapterTopic.TheoryStartDate,
                                EndDateErr = curriculumChapter.EndDate < curriculumChapterTopic.TheoryEndDate ||
                                             curriculumChapter.EndDate < curriculumChapterTopic.TestEndDate
                            }
                        });
                    }
                    else if (curriculum.StartDate > curriculumChapterTopic.TestStartDate ||
                             curriculum.StartDate > curriculumChapterTopic.TheoryStartDate ||
                             curriculum.EndDate < curriculumChapterTopic.TheoryEndDate ||
                             curriculum.EndDate < curriculumChapterTopic.TestEndDate)
                    {
                        errors.ErrorsText.Add(Localization.GetMessage("TopicTimelineOutOfCurriculum") + " - " + curriculumChapterTopic.Topic.Name);
                        errors.Errors.Add(new ValidationError {
                            Type      = ValidationErrorType.TopicTimelineOutOfCurriculum,
                            ErrorData = new {
                                CurriculumChapterId      = curriculumChapter.Id,
                                CurriculumChapterTopicId = curriculumChapterTopic.Id,
                                StartDateErr             = curriculum.StartDate > curriculumChapterTopic.TestStartDate ||
                                                           curriculum.StartDate > curriculumChapterTopic.TheoryStartDate,
                                EndDateErr = curriculum.EndDate < curriculumChapterTopic.TheoryEndDate ||
                                             curriculum.EndDate < curriculumChapterTopic.TestEndDate
                            }
                        });
                    }
                }
            }

            return(errors);
        }