Esempio n. 1
0
 public void ValidateAdmitionDate(DateTime?admitionDate, OperationResponseBase response, string fieldname)
 {
     if (admitionDate == DateTime.MinValue || admitionDate == null)
     {
         response.AddError("002", $"{fieldname} value: {admitionDate} can't be null or zero");
     }
     else if (admitionDate > DateTime.MinValue && admitionDate > DateTime.Today)
     {
         response.AddError("008", $"{fieldname} value: {admitionDate} can't be bigger than today");
     }
 }
Esempio n. 2
0
 public void Shift(string shift, OperationResponseBase response, string lineWithError)
 {
     if (!this._isNullOrZeroValidator.Execute(shift, response, "Shift"))
     {
         if (!char.IsUpper(shift[0]))
         {
             response.AddError("028", $"{lineWithError} First letter of shift must be in uppercase.");
         }
         else if (shift != "Manhã" && shift != "Tarde" && shift != "Noite")
         {
             response.AddError("029", $"{lineWithError} Invalid Shift! Valid shifts: Manhã, Tarde, Noite");
         }
     }
 }
Esempio n. 3
0
 public void ValidateTeacherId(long?value, OperationResponseBase response)
 {
     if (value == null || value <= 0)
     {
         response.AddError("002", $"TeacherId can't be null or zero.");
     }
 }
Esempio n. 4
0
 public void ValidatePageNumber(int?pageNumber, OperationResponseBase response)
 {
     if (pageNumber <= 0 || pageNumber == null)
     {
         response.AddError("002", $"Page number: {pageNumber} can't be null or zero.");
     }
 }
Esempio n. 5
0
        public void ValidateSalary(decimal?minSalary, decimal?maxSalary, OperationResponseBase response)
        {
            if (minSalary != null && maxSalary != null)
            {
                this._parametersValidator.ValidateSalary(minSalary, response, nameof(minSalary));

                this._parametersValidator.ValidateSalary(maxSalary, response, nameof(maxSalary));

                if (maxSalary < minSalary)
                {
                    response.AddError("019", $"{nameof(maxSalary)} can't be bigger than {nameof(minSalary)}");
                }
            }
            else if (minSalary != null ^ maxSalary != null)
            {
                if (maxSalary != null)
                {
                    this._parametersValidator.ValidateSalary(minSalary, response, nameof(minSalary));
                }
                else if (maxSalary != null)
                {
                    this._parametersValidator.ValidateSalary(maxSalary, response, nameof(maxSalary));
                }
            }
        }
Esempio n. 6
0
        public void ValidateAdmitionDate(DateTime?minAdmitionDate, DateTime?maxAdmitionDate, OperationResponseBase response)
        {
            if (minAdmitionDate != null && maxAdmitionDate != null)
            {
                this._parametersValidator.ValidateAdmitionDate(minAdmitionDate, response, nameof(minAdmitionDate));

                this._parametersValidator.ValidateAdmitionDate(maxAdmitionDate, response, nameof(maxAdmitionDate));

                if (maxAdmitionDate < minAdmitionDate)
                {
                    response.AddError("019", $"{nameof(maxAdmitionDate)} can't be bigger than {nameof(minAdmitionDate)}");
                }
            }
            else if (minAdmitionDate != null ^ maxAdmitionDate != null)
            {
                if (minAdmitionDate != null)
                {
                    this._parametersValidator.ValidateAdmitionDate(minAdmitionDate, response, nameof(minAdmitionDate));
                }
                else if (maxAdmitionDate != null)
                {
                    this._parametersValidator.ValidateAdmitionDate(maxAdmitionDate, response, nameof(maxAdmitionDate));
                }
            }
        }
Esempio n. 7
0
 public void ValidateGender(char?gender, OperationResponseBase response)
 {
     if (!this.IsGenderValid(gender))
     {
         response.AddError("005", $"Invalid gender value: {gender}! Gender must be 'M' or 'F'");
     }
 }
Esempio n. 8
0
 public void ValidateSalary(decimal?salary, OperationResponseBase response, string filedname)
 {
     if (salary > ModelConstants.Teacher.MaxSalary || salary < ModelConstants.Teacher.MinSalary)
     {
         response.AddError("007", $"{filedname} value: {salary} don't accepted! Choose a value between {ModelConstants.Teacher.MinSalary} and {ModelConstants.Teacher.MaxSalary}");
     }
 }
Esempio n. 9
0
 private void StartTime(TimeSpan startTime, OperationResponseBase response, string lineWithError)
 {
     if (startTime < TimeSpan.FromHours(8))
     {
         response.AddError("032", $"{lineWithError} The course can't start before 8:00");
     }
 }
Esempio n. 10
0
 private void EndTime(TimeSpan endTime, OperationResponseBase response, string lineWithError)
 {
     if (endTime < TimeSpan.FromHours(8))
     {
         response.AddError("033", $"{lineWithError} The course can't end after 22:00");
     }
 }
Esempio n. 11
0
        public void Time(TimeSpan startTime, TimeSpan endTime, OperationResponseBase response, string lineWithError)
        {
            if (!this._isNullOrZeroValidator.Execute(startTime, response, "StartTime") && !this._isNullOrZeroValidator.Execute(endTime, response, "EndTime"))
            {
                StartTime(startTime, response, lineWithError);

                EndTime(endTime, response, lineWithError);

                if (startTime > endTime)
                {
                    response.AddError("031", $"{lineWithError} StartTime can't be bigger than EndTime");
                }
                else if (endTime - startTime > TimeSpan.FromHours(3))
                {
                    response.AddError("034", $"{lineWithError} Duration can't be bigger than 3h");
                }
            }
        }
Esempio n. 12
0
        public void ValidateLevel(char?level, OperationResponseBase response)
        {
            IEnumerable <char> levels = this._levelRepository.ListAll();

            if (!levels.Any(l => l == level))
            {
                response.AddError("005", $"Invalid level value: {level}! Valid levels: {string.Join(", ",levels.ToArray())}");
            }
        }
Esempio n. 13
0
 public void Course(string course, OperationResponseBase response, string lineWithError)
 {
     if (!this._isNullOrZeroValidator.Execute(course, response, "Course"))
     {
         if (!this._courseRepository.ExistByName(course))
         {
             response.AddError("027", $"{lineWithError} Invalid course.");
         }
     }
 }
Esempio n. 14
0
 public void Teacher(string teacher, OperationResponseBase response, string lineWithError)
 {
     if (!this._isNullOrZeroValidator.Execute(teacher, response, "Teacher"))
     {
         if (!this._teacherRepository.ExistByName(teacher))
         {
             response.AddError("026", $"{lineWithError} Invalid teacher.");
         }
     }
 }
Esempio n. 15
0
 public void ClassId(int classId, OperationResponseBase response, string lineWithError)
 {
     if (!this._isNullOrZeroValidator.Execute(classId, response, "Id"))
     {
         if (this._classRepository.ExistByClassId(classId) == true)
         {
             response.AddError("025", $"{lineWithError} ClassId already exist.");
         }
     }
 }
Esempio n. 16
0
        public void ValidateName(string name, OperationResponseBase response)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                response.AddError("002", $"Name can't be null or empty.");

                return;
            }

            if (name.Length > ModelConstants.Teacher.NameMaxLength)
            {
                response.AddError("004", $"Invalid name length: {name.Length} exceeded the limit! Max: {ModelConstants.Teacher.NameMaxLength}.");
            }

            if (name.Any(c => char.IsSymbol(c)) || name.Any(c => char.IsNumber(c)))
            {
                response.AddError("020", $"Name can't have specials characters.");
            }
        }
Esempio n. 17
0
 public void Date(DateTime startDate, DateTime endDate, OperationResponseBase response, string lineWithError)
 {
     if (!this._isNullOrZeroValidator.Execute(startDate, response, "StartDate") && !this._isNullOrZeroValidator.Execute(endDate, response, "EndDate"))
     {
         if (startDate > endDate)
         {
             response.AddError("030", $"{lineWithError} StartDate can't be bigger than EndDate");
         }
     }
 }
Esempio n. 18
0
 public void ValidatePageSize(int?pageSize, OperationResponseBase response)
 {
     if (pageSize <= 0 || pageSize == null)
     {
         response.AddError("002", $"Page size: {pageSize} can't be null or zero.");
     }
     else if (pageSize > ModelConstants.Teacher.MaxTeachersPerPage)
     {
         response.Errors.Add(new OperationError("015", $"Page size value: {pageSize} exceeded the limit."));
     }
 }
Esempio n. 19
0
        public bool Execute(TimeSpan?time, OperationResponseBase response, string fieldname)
        {
            if (time == null || time == TimeSpan.Zero)
            {
                response.AddError("002", $"{fieldname} can't be null or zero.");

                return(true);
            }

            return(false);
        }
Esempio n. 20
0
        public bool Execute(DateTime?date, OperationResponseBase response, string fieldname)
        {
            if (date == null || date == DateTime.MinValue)
            {
                response.AddError("002", $"{fieldname} can't be null or zero.");

                return(true);
            }

            return(false);
        }
Esempio n. 21
0
        public bool Execute(int?num, OperationResponseBase response, string fieldname)
        {
            if (num == 0 || num == null)
            {
                response.AddError("002", $"{fieldname} can't be null or zero.");

                return(true);
            }

            return(false);
        }
Esempio n. 22
0
        public bool Execute(string str, OperationResponseBase response, string fieldname)
        {
            if (!string.IsNullOrWhiteSpace(str))
            {
                response.AddError("002", $"{fieldname} can't be null or zero.");

                return(true);
            }

            return(false);
        }
Esempio n. 23
0
        public void ValidateLevelIds(List <char> levelIds, OperationResponseBase response)
        {
            if (levelIds.Count > 0)
            {
                List <char> validLevels = this._levelRepository.ListAll().ToList();

                List <char> invalidLevels = levelIds.Except(validLevels).ToList();

                if (invalidLevels.Count > 0)
                {
                    response.AddError("017", $"Error in levelIds. Invalid values: {string.Join(", ", invalidLevels)}.");
                }
            }
        }
Esempio n. 24
0
        public void ValidateGenders(List <char> genders, OperationResponseBase response)
        {
            if (genders.Count > 0)
            {
                List <char> validGenders = new List <char> {
                    'M', 'F'
                };
                List <char> invalidGenders = genders.Except(validGenders).ToList();

                if (invalidGenders.Count > 0)
                {
                    response.AddError("017", $"Error in levelIds. Invalid values: {string.Join(", ", invalidGenders)}.");
                }
            }
        }
Esempio n. 25
0
        public void ValidateTeacher(Teacher teacher, OperationResponseBase response)
        {
            if (teacher == null)
            {
                response.AddError("001", "Request can't be null");

                return;
            }

            this._validator.ValidateTeacherId(teacher.TeacherId, response);

            this._validator.ValidateName(teacher.Name, response);

            this._validator.ValidateGender(teacher.Gender, response);

            this._validator.ValidateLevel(teacher.LevelId, response);

            this._validator.ValidateSalary(teacher.Salary, response, nameof(teacher.Salary));

            this._validator.ValidateAdmitionDate(teacher.AdmitionDate, response, nameof(teacher.AdmitionDate));
        }