Esempio n. 1
0
        /// <summary>
        /// Validates the curriculum.
        /// </summary>
        /// <param name="curriculum">The curriculum.</param>
        /// <returns></returns>
        public ValidationStatus ValidateCurriculum(Curriculum curriculum)
        {
            var validationStatus = new ValidationStatus();
            var currentGroupId   = -1;

            // If update old curriculum
            if (curriculum.Id > 0)
            {
                var oldCurriculum = this.Storage.GetCurriculum(curriculum.Id);
                currentGroupId           = oldCurriculum.UserGroupRef;
                curriculum.DisciplineRef = oldCurriculum.DisciplineRef;
            }

            if (curriculum.UserGroupRef > 0 && curriculum.DisciplineRef > 0)
            {
                var curriculums = this.Storage.GetCurriculums(c => c.DisciplineRef == curriculum.DisciplineRef).ToList();
                if (curriculums.Exists(item => item.UserGroupRef == curriculum.UserGroupRef) && curriculum.UserGroupRef != currentGroupId)
                {
                    validationStatus.AddLocalizedError("ChooseAnotherGroupForThisCurriculum");
                }
            }
            if (curriculum.UserGroupRef <= 0)
            {
                validationStatus.AddLocalizedError("ChooseGroup");
            }
            if (curriculum.DisciplineRef <= 0)
            {
                validationStatus.AddLocalizedError("ChooseDiscipline");
            }

            ValidateDate(curriculum.StartDate, curriculum.EndDate, validationStatus);

            return(validationStatus);
        }
Esempio n. 2
0
        /// <summary>
        /// Validates the curriculum.
        /// </summary>
        /// <param name="curriculum">The curriculum.</param>
        /// <returns></returns>
        public ValidationStatus ValidateCurriculum(Curriculum curriculum)
        {
            var validationStatus = new ValidationStatus();
            var currentGroupId = -1;
            // If update old curriculum
            if (curriculum.Id > 0)
            {
                var oldCurriculum = this.Storage.GetCurriculum(curriculum.Id);
                currentGroupId = oldCurriculum.UserGroupRef;
                curriculum.DisciplineRef = oldCurriculum.DisciplineRef;
            }

            if (curriculum.UserGroupRef > 0 && curriculum.DisciplineRef > 0)
            {
                var curriculums = this.Storage.GetCurriculums(c => c.DisciplineRef == curriculum.DisciplineRef).ToList();
                if (curriculums.Exists(item => item.UserGroupRef == curriculum.UserGroupRef) && curriculum.UserGroupRef != currentGroupId)
                {
                    validationStatus.AddLocalizedError("ChooseAnotherGroupForThisCurriculum");
                }
            }
            if (curriculum.UserGroupRef <= 0)
            {
                validationStatus.AddLocalizedError("ChooseGroup");
            }
            if (curriculum.DisciplineRef <= 0)
            {
                validationStatus.AddLocalizedError("ChooseDiscipline");
            }

            ValidateDate(curriculum.StartDate, curriculum.EndDate, validationStatus);

            return validationStatus;
        }
Esempio n. 3
0
        private static void ValidateDate(DateTime?startDate, DateTime?endDate, ValidationStatus validationStatus)
        {
            var minAllowedDate = Constants.MinAllowedDateTime;
            var maxAllowedDate = Constants.MaxAllowedDateTime;

            if (endDate.HasValue ^ startDate.HasValue)
            {
                validationStatus.AddLocalizedError("ChooseStartAndEndDate");
            }
            else if (endDate.HasValue)
            {
                if (startDate >= endDate)
                {
                    validationStatus.AddLocalizedError("StartDateMustLessThanEndDate");
                }

                if (startDate < minAllowedDate || startDate > maxAllowedDate)
                {
                    validationStatus.AddLocalizedError("StartDateMustBeBetween", minAllowedDate.ToString(), maxAllowedDate.ToString());
                }

                if (endDate < minAllowedDate || endDate > maxAllowedDate)
                {
                    validationStatus.AddLocalizedError("EndDateMustBeBetween", minAllowedDate.ToString(), maxAllowedDate.ToString());
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Validates the topic.
        /// </summary>
        /// <param name="data">The topic.</param>
        /// <returns></returns>
        public ValidationStatus ValidateTopic(Topic data)
        {
            ValidationStatus validationStatus = new ValidationStatus();

            if (String.IsNullOrEmpty(data.Name))
            {
                validationStatus.AddLocalizedError("NameReqiured");
            }
            else if (data.Name.Length > Constants.MaxStringFieldLength)
            {
                validationStatus.AddLocalizedError("NameCanNotBeLongerThan", Constants.MaxStringFieldLength);
            }

            if (!data.TestCourseRef.HasValue && !data.TheoryCourseRef.HasValue)
            {
                validationStatus.AddLocalizedError("ChooseAtLeastOneCourse");
            }
            else
            {
                if (data.TestCourseRef.HasValue)
                {
                    if (data.TestTopicTypeRef == 0)
                    {
                        validationStatus.AddLocalizedError("ChooseTopicType");
                    }
                    else
                    {
                        var testTopicType = Converter.ToTopicType(storage.GetTopicType(data.TestTopicTypeRef.Value));
                        if (testTopicType == TopicTypeEnum.TestWithoutCourse && data.TestCourseRef != Constants.NoCourseId)
                        {
                            validationStatus.AddLocalizedError("TestWithoutCourse");
                        }
                        if (testTopicType != TopicTypeEnum.TestWithoutCourse && (!data.TestCourseRef.HasValue || data.TestCourseRef <= 0))
                        {
                            validationStatus.AddLocalizedError("ChooseTestCourse");
                        }
                    }
                }

                if (data.TheoryCourseRef.HasValue)
                {
                    if (data.TheoryTopicTypeRef == 0)
                    {
                        validationStatus.AddLocalizedError("ChooseTopicType");
                    }
                    else
                    {
                        if (!data.TheoryCourseRef.HasValue || data.TheoryCourseRef <= 0)
                        {
                            validationStatus.AddLocalizedError("ChooseTheoryCourse");
                        }
                    }
                }
            }

            return(validationStatus);
        }
Esempio n. 5
0
        /// <summary>
        /// Validates the topic.
        /// </summary>
        /// <param name="data">The topic.</param>
        /// <returns></returns>
        public ValidationStatus ValidateTopic(Topic data)
        {
            ValidationStatus validationStatus = new ValidationStatus();
            if (String.IsNullOrEmpty(data.Name))
            {
                validationStatus.AddLocalizedError("NameReqiured");
            }
            else if (data.Name.Length > Constants.MaxStringFieldLength)
            {
                validationStatus.AddLocalizedError("NameCanNotBeLongerThan", Constants.MaxStringFieldLength);
            }

            if (!data.TestCourseRef.HasValue && !data.TheoryCourseRef.HasValue)
            {
                validationStatus.AddLocalizedError("ChooseAtLeastOneCourse");
            }
            else
            {
                if (data.TestCourseRef.HasValue)
                {
                    if (data.TestTopicTypeRef == 0)
                    {
                        validationStatus.AddLocalizedError("ChooseTopicType");
                    }
                    else
                    {
                        var testTopicType = Converter.ToTopicType(storage.GetTopicType(data.TestTopicTypeRef.Value));
                        if (testTopicType == TopicTypeEnum.TestWithoutCourse && data.TestCourseRef != Constants.NoCourseId)
                        {
                            validationStatus.AddLocalizedError("TestWithoutCourse");
                        }
                        if (testTopicType != TopicTypeEnum.TestWithoutCourse && (!data.TestCourseRef.HasValue || data.TestCourseRef <= 0))
                        {
                            validationStatus.AddLocalizedError("ChooseTestCourse");
                        }
                    }
                }

                if (data.TheoryCourseRef.HasValue)
                {
                    if (data.TheoryTopicTypeRef == 0)
                    {
                        validationStatus.AddLocalizedError("ChooseTopicType");
                    }
                    else
                    {
                        if (!data.TheoryCourseRef.HasValue || data.TheoryCourseRef <= 0)
                        {
                            validationStatus.AddLocalizedError("ChooseTheoryCourse");
                        }
                    }
                }
            }

            return validationStatus;
        }
Esempio n. 6
0
        /// <summary>
        /// Validates the curriculum.
        /// </summary>
        /// <param name="curriculum">The curriculum.</param>
        /// <returns></returns>
        public ValidationStatus ValidateCurriculum(Curriculum curriculum)
        {
            ValidationStatus validationStatus = new ValidationStatus();

            if (curriculum.UserGroupRef <= 0)
            {
                validationStatus.AddLocalizedError("ChooseGroup");
            }
            ValidateDate(curriculum.StartDate, curriculum.EndDate, validationStatus);

            return validationStatus;
        }
Esempio n. 7
0
        /// <summary>
        /// Validates the curriculum.
        /// </summary>
        /// <param name="curriculum">The curriculum.</param>
        /// <returns></returns>
        public ValidationStatus ValidateCurriculum(Curriculum curriculum)
        {
            ValidationStatus validationStatus = new ValidationStatus();

            if (curriculum.UserGroupRef <= 0)
            {
                validationStatus.AddLocalizedError("ChooseGroup");
            }
            ValidateDate(curriculum.StartDate, curriculum.EndDate, validationStatus);

            return(validationStatus);
        }
Esempio n. 8
0
        /// <summary>
        /// Validates the curriculum chapter topic.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public ValidationStatus ValidateCurriculumChapterTopic(CurriculumChapterTopic data)
        {
            var validationStatus = new ValidationStatus();

            ValidateDate(data.TestStartDate, data.TestEndDate, validationStatus);
            ValidateDate(data.TheoryStartDate, data.TheoryEndDate, validationStatus);

            if (data.ThresholdOfSuccess <= 0)
            {
                validationStatus.AddLocalizedError("MaxScoreMustBeGreaterThanZero");
            }

            return validationStatus;
        }
Esempio n. 9
0
        /// <summary>
        /// Validates the curriculum chapter topic.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public ValidationStatus ValidateCurriculumChapterTopic(CurriculumChapterTopic data)
        {
            var validationStatus = new ValidationStatus();

            ValidateDate(data.TestStartDate, data.TestEndDate, validationStatus);
            ValidateDate(data.TheoryStartDate, data.TheoryEndDate, validationStatus);

            if (data.ThresholdOfSuccess <= 0)
            {
                validationStatus.AddLocalizedError("MaxScoreMustBeGreaterThanZero");
            }

            return(validationStatus);
        }
Esempio n. 10
0
 private void ValidateDate(DateTime? startDate, DateTime? endDate, ValidationStatus validationStatus)
 {
     DateTime minAllowedDate = Constants.MinAllowedDateTime;
     DateTime maxAllowedDate = Constants.MaxAllowedDateTime;
     if (endDate.HasValue ^ startDate.HasValue)
     {
         validationStatus.AddLocalizedError("ChooseStartAndEndDate");
     }
     else if (endDate.HasValue && startDate.HasValue)
     {
         if (startDate > endDate)
         {
             validationStatus.AddLocalizedError("StartDateMustLessThanEndDate");
         }
         if (startDate < minAllowedDate || startDate > maxAllowedDate)
         {
             validationStatus.AddLocalizedError("StartDateMustBeBetween", minAllowedDate.ToString(), maxAllowedDate.ToString());
         }
         if (endDate < minAllowedDate || endDate > maxAllowedDate)
         {
             validationStatus.AddLocalizedError("EndDateMustBeBetween", minAllowedDate.ToString(), maxAllowedDate.ToString());
         }
     }
 }