Beispiel #1
0
        public void Validation(string daysOfWeek, bool isClashException = true)
        {
            var         modelName  = isClashException ? "Clash exception" : "Clash";
            IValidation validation = new RequiredFieldValidation
            {
                Field = new List <ValidationInfo>
                {
                    new ValidationInfo {
                        FieldName = $"{modelName} time and DOWs - days of week", FieldToValidate = daysOfWeek
                    }
                }
            };

            validation.Execute();

            const string zeroOrOne = "^(?!0{7})[0-1]{7}$";

            validation = new RegexValidation
            {
                Field = new List <ValidationInfo>
                {
                    new ValidationInfo
                    {
                        ErrorMessage    = $"{modelName} time and DOWs - Invalid days of week",
                        FieldToValidate = daysOfWeek,
                        RegexPattern    = zeroOrOne
                    }
                }
            };
            validation.Execute();
        }
Beispiel #2
0
        public void RegexValidation(string fromTime, string toTime, List <string> dowPattern)
        {
            const string hhmmFormat = "^([0-9]|0[0-9]|1?[0-9]|2[0-3]):[0-5][0-9]$";
            const string dayOfWeek  = "^\\b(?i)(Sun|Mon|Tue|Wed|Thu|Fri|Sat)\\b$";
            IValidation  validation = new RegexValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        ErrorMessage = "Invalid Time Slice From Time", FieldToValidate = fromTime, RegexPattern = hhmmFormat
                    },
                    new ValidationInfo()
                    {
                        ErrorMessage = "Invalid Time Slice To Time", FieldToValidate = ToTime, RegexPattern = hhmmFormat
                    },
                    new ValidationInfo()
                    {
                        ErrorMessage = "Invalid Dow Pattern", FieldToValidate = dowPattern, RegexPattern = dayOfWeek
                    }
                }
            };

            validation.Execute();
        }
Beispiel #3
0
        }                                      //0 or 1 for each day of week

        internal void Validate(IEnumerable <SalesArea> validSalesAreas)
        {
            ValidateDates();

            ValidateTimes();

            IValidation validation = new RequiredFieldValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        FieldName = "PassSalesAreaPriority DaysOfWeek", FieldToValidate = DaysOfWeek
                    },
                    new ValidationInfo()
                    {
                        FieldName = "PassSalesAreaPriority SalesAreaPriorities", FieldToValidate = SalesAreaPriorities
                    },
                }
            };

            validation.Execute();

            validation = new RegexValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        ErrorMessage    = "Invalid PassSalesAreaPriority DaysOfWeek",
                        FieldToValidate = DaysOfWeek,
                        RegexPattern    = ZeroOrOne
                    }
                }
            };
            validation.Execute();

            var allSalesAreaPriorities       = SalesAreaPriorities.Select(x => x.SalesArea);
            var duplicateSalesAreaPriorities = allSalesAreaPriorities.GroupBy(salesArea => salesArea).Where(g => g.Count() > 1).Select(g => g.Key);

            if (duplicateSalesAreaPriorities.Count() > 0)
            {
                throw new Exception("Duplicate SalesAreas: " + string.Join(",", duplicateSalesAreaPriorities.ToArray()));
            }

            if (validSalesAreas != null)
            {
                SalesAreaPriorities.ForEach(salesAreaPriority =>
                {
                    if (!validSalesAreas.Any(validSalesArea => string.Equals(validSalesArea.Name, salesAreaPriority.SalesArea, StringComparison.CurrentCulture)))
                    {
                        throw new Exception(salesAreaPriority.SalesArea + " is not a valid SalesArea");
                    }
                });
            }
        }
        private void ValidateRestrictionDatesAndDays(DateTime startDate, DateTime?endDate, string restrictionDays)
        {
            IValidation validation = new RequiredFieldValidation
            {
                Field = new List <ValidationInfo>
                {
                    new ValidationInfo {
                        FieldName = "Start Date", FieldToValidate = startDate
                    },
                    new ValidationInfo {
                        FieldName = "Restriction Days", FieldToValidate = restrictionDays
                    }
                }
            };

            validation.Execute();

            if (endDate.HasValue)
            {
                validation = new CompareValidation
                {
                    Field = new List <ValidationInfo>
                    {
                        new ValidationInfo
                        {
                            ErrorMessage    = "Restriction start date should be less than or equal to end date",
                            FieldToValidate = startDate.Date,
                            FieldToCompare  = endDate?.Date,
                            Operator        = Operator.LessThanEqual
                        }
                    }
                };
                validation.Execute();
            }
            const string zeroOrOne = "^(?!0{7})[0-1]{7}$";

            validation = new RegexValidation
            {
                Field = new List <ValidationInfo>
                {
                    new ValidationInfo
                    {
                        ErrorMessage    = "Invalid Restriction Days",
                        FieldToValidate = restrictionDays,
                        RegexPattern    = zeroOrOne
                    }
                }
            };
            validation.Execute();
        }