Esempio n. 1
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. 2
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. 3
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. 4
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. 5
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. 6
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. 7
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. 8
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. 9
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. 10
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. 11
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. 12
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. 13
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. 14
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. 15
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. 16
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. 17
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. 18
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. 19
0
        /// <summary>
        /// This method builds the HTTP response .
        /// </summary>
        /// <typeparam name="TResponseData"></typeparam>
        /// <param name="response"></param>
        /// <returns></returns>
        public static JsonResult BuildHttpResponse <TResponseData>(this OperationResponseBase <TResponseData> response)
            where TResponseData : OperationResponseData
        {
            // BadRequest Status Code.
            if (response.HttpStatusCode == HttpStatusCode.BadRequest)
            {
                response.SetBadRequestError();

                return(new JsonResult(response)
                {
                    StatusCode = (int)HttpStatusCode.BadRequest
                });
            }

            // Unauthorized Status Code.
            if (response.HttpStatusCode == HttpStatusCode.Unauthorized)
            {
                response.SetUnauthorizedError();

                return(new JsonResult(response)
                {
                    StatusCode = (int)HttpStatusCode.Unauthorized
                });
            }

            // InternalServerError Status Code.
            if (response.HttpStatusCode == HttpStatusCode.InternalServerError)
            {
                response.SetInternalServerError();

                return(new JsonResult(response)
                {
                    StatusCode = (int)HttpStatusCode.InternalServerError
                });
            }

            // NotImplemented Status Code.
            if (response.HttpStatusCode == HttpStatusCode.NotImplemented)
            {
                response.SetNotImplementedError();

                return(new JsonResult(response)
                {
                    StatusCode = (int)HttpStatusCode.NotImplemented
                });
            }

            response.SetSuccessCreated();
            return(new JsonResult(response)
            {
                StatusCode = (int)HttpStatusCode.Created
            });
        }
Esempio n. 20
0
        public void ValidateName_Should_WorkCorrectly(string input, bool isValid, int errorCount)
        {
            // Arrange
            OperationResponseBase response = new OperationResponseBase();

            // Act
            this._validator.ValidateName(input, response);

            // Assert
            response.Success.Should().Be(isValid);
            response.Errors.Count.Should().Be(errorCount);
        }
Esempio n. 21
0
        public void ValidateTeacherId_Should_AddError_When_ReceiveNullOrZero_And_DoNothing_Otherwise(long?input, bool isValid)
        {
            // Arrange
            OperationResponseBase responseBase = new OperationResponseBase();
            int errorCount = isValid ? 0 : 1;

            // Act
            this._validator.ValidateTeacherId(input, responseBase);

            // Assert
            responseBase.Success.Should().Be(isValid);
            responseBase.Errors.Count.Should().Be(errorCount);
        }
Esempio n. 22
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. 23
0
        public void ValidateAdmitionDate_Should_HaveNoError_When_Between1000And10000_And_AddError_Otherwise(decimal?input, bool isValid)
        {
            // Arrange
            int errorCount = isValid ? 0 : 1;

            OperationResponseBase responseBase = new OperationResponseBase();

            // Act
            this._validator.ValidateSalary(input, responseBase, "Teste");

            // Assert
            responseBase.Success.Should().Be(isValid);
            responseBase.Errors.Count.Should().Be(errorCount);
        }
Esempio n. 24
0
        public void ValidateGender_Should_HaveNoError_When_FOrM_And_AddError_Otherwise(char?input, bool isValid)
        {
            // Arrange
            int errorCount = isValid ? 0 : 1;

            OperationResponseBase responseBase = new OperationResponseBase();

            // Act
            this._validator.ValidateGender(input, responseBase);

            // Assert
            responseBase.Success.Should().Be(isValid);
            responseBase.Errors.Count.Should().Be(errorCount);
        }
Esempio n. 25
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. 26
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. 27
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. 28
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. 29
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));
        }
Esempio n. 30
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));
                }
            }
        }