Beispiel #1
0
        public void RequiredFieldValidation(DateTime startDate, DateTime endDate, List <Length> lengths, List <DayPart> dayParts, int spotMaxRatings)
        {
            IValidation validation = new RequiredFieldValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        FieldName = "Strike Weight Start Date", FieldToValidate = startDate
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Strike Weight End Date", FieldToValidate = endDate
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Strike Weight Lengths", FieldToValidate = lengths
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Day Parts", FieldToValidate = dayParts
                    }
                }
            };

            validation.Execute();
            if (lengths != null && lengths.Any())
            {
                lengths.ForEach(l => l.Validation(l.length));
            }

            if (dayParts != null && dayParts.Any())
            {
                dayParts.ForEach(d => d.Validation());
            }

            validation = new CompareValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        ErrorMessage    = "Strike Weight Spot Max Ratings should be greater than or equal to 0",
                        FieldToValidate = spotMaxRatings,
                        FieldToCompare  = 0,
                        Operator        = Operator.GreaterThanEqual
                    }
                }
            };
            validation.Execute();
        }
        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();
        }
Beispiel #3
0
        private void Validate(string salesArea, string demographic, DateTime startDate, DateTime endDate,
                              int universeValue)

        {
            IValidation validation = new RequiredFieldValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        FieldName = "Sales Area", FieldToValidate = salesArea
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Demographic", FieldToValidate = demographic
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Start Date", FieldToValidate = startDate
                    },
                    new ValidationInfo()
                    {
                        FieldName = "End Date", FieldToValidate = endDate
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Universe Value", FieldToValidate = universeValue
                    }
                }
            };

            validation.Execute();

            validation = new CompareValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        ErrorMessage    = "Universe start date should be less than or equal to end date",
                        FieldToValidate = startDate,
                        FieldToCompare  = endDate,
                        Operator        = Operator.LessThanEqual
                    }
                }
            };
            validation.Execute();
        }
Beispiel #4
0
        public static void Validation(DateTime startDate, DateTime?endDate, List <TimeAndDow> timeAndDows)
        {
            IValidation validation = new RequiredFieldValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        FieldName = "Clash exception time and DOWs", FieldToValidate = timeAndDows
                    }
                }
            };

            validation.Execute();

            if (timeAndDows.Any())
            {
                timeAndDows.ForEach(t => t.Validation(t.DaysOfWeek));
            }

            if (endDate != null)
            {
                validation = new CompareValidation()
                {
                    Field = new List <ValidationInfo>()
                    {
                        new ValidationInfo()
                        {
                            ErrorMessage    = "Clash exception end date should not be a date in the past",
                            FieldToValidate = endDate.Value.Date,
                            FieldToCompare  = DateTime.Today.Date,
                            Operator        = Operator.GreaterThanEqual
                        },
                        new ValidationInfo()
                        {
                            ErrorMessage    = "Clash exception end date should be greater than or equal to start date",
                            FieldToValidate = endDate.Value.Date,
                            FieldToCompare  = startDate.Date,
                            Operator        = Operator.GreaterThanEqual
                        }
                    }
                };
                validation.Execute();
            }
        }
Beispiel #5
0
        public void CompareValidation(DateTime startDate, DateTime endDate)
        {
            IValidation validation = new CompareValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        ErrorMessage    = "Strike weight start date should be less than or equal to end date",
                        FieldToValidate = startDate,
                        FieldToCompare  = endDate,
                        Operator        = Operator.LessThanEqual
                    }
                }
            };

            validation.Execute();
        }
Beispiel #6
0
        public void Validation()
        {
            IValidation validation = new RequiredFieldValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        FieldName = "Time Slices", FieldToValidate = Timeslices
                    }
                }
            };

            validation.Execute();
            if (Timeslices != null && Timeslices.Any())
            {
                Timeslices.ForEach(t => t.RequiredFieldValidation(t.FromTime, t.ToTime, t.DowPattern));
                Timeslices.ForEach(t => t.RegexValidation(t.FromTime, t.ToTime, t.DowPattern));
            }

            validation = new CompareValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        ErrorMessage    = "Day Part Spot Max Ratings should be greater than or equal to 0",
                        FieldToValidate = SpotMaxRatings,
                        FieldToCompare  = 0,
                        Operator        = Operator.GreaterThanEqual
                    },
                    new ValidationInfo()
                    {
                        ErrorMessage    = "Day Part Campaign Price should be greater than or equal to 0",
                        FieldToValidate = CampaignPrice,
                        FieldToCompare  = 0,
                        Operator        = Operator.GreaterThanEqual
                    }
                }
            };
            validation.Execute();
        }
Beispiel #7
0
        private void Validation(
            string externalId,
            string name,
            string demographic,
            DateTime startDateTime,
            DateTime endDateTime,
            string product,
            string deliveryType,
            decimal?targetRatings,
            List <model.External.Campaign.SalesAreaCampaignTargetViewModel> salesAreaCampaignTargets,
            List <TimeRestriction> timeRestrictions,
            List <ProgrammeRestriction> programmeRestrictions,
            List <CampaignProgramme> campaignProgrammes,
            string campaignGroup,
            string includeRightSizer,
            bool includeOptimisation,
            int campaignPassPriority,
            int campaignSpotMaxRatings,
            bool validateCampaignPassPriority,
            bool validateDeliveryType)
        {
            IValidation validation = new RequiredFieldValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        FieldName = "External Id", FieldToValidate = externalId
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Campaign Name", FieldToValidate = name
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Demographic", FieldToValidate = demographic
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Start Date Time", FieldToValidate = startDateTime
                    },
                    new ValidationInfo()
                    {
                        FieldName = "End Date Time", FieldToValidate = endDateTime
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Product", FieldToValidate = product
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Target Ratings", FieldToValidate = targetRatings
                    },
                    new ValidationInfo()
                    {
                        FieldName       = "Sales Area Campaign Targets",
                        FieldToValidate = salesAreaCampaignTargets
                    },
                    new ValidationInfo()
                    {
                        FieldName = "Include Right Sizer", FieldToValidate = includeRightSizer
                    }
                }
            };

            if (validateDeliveryType)
            {
                validation.Field.Add(new ValidationInfo()
                {
                    FieldName = "Delivery Type", FieldToValidate = deliveryType
                });
            }

            validation.Execute();

            if (validateCampaignPassPriority)
            {
                ValidateCampaignPassPriority(includeOptimisation, campaignPassPriority);
            }

            if (!EnumUtilities.ToDescriptionList <IncludeRightSizer>().Select(value => value.ToUpper())
                .Contains(includeRightSizer.ToUpper()))
            {
                throw new ArgumentException($"Invalid right sizer value: ${includeRightSizer}",
                                            ReflectionUtilities.PropertyName <CreateCampaign>(c => c.IncludeRightSizer));
            }

            if (validateDeliveryType && !Enum.IsDefined(typeof(CampaignDeliveryType), deliveryType))
            {
                throw new ArgumentException($"Invalid delivery type value: ${deliveryType}", ReflectionUtilities.PropertyName <CreateCampaign>(c => c.DeliveryType));
            }

            if (campaignGroup != null)
            {
                validation = new LengthValidation()
                {
                    Field = new List <ValidationInfo>()
                    {
                        new ValidationInfo()
                        {
                            ErrorMessage    = "Campaign Group can't be more than 20 characters: " + campaignGroup,
                            FieldToValidate = campaignGroup,
                            LengthToCompare = 20,
                            Operator        = Operator.LessThanEqual
                        }
                    }
                };
                validation.Execute();
            }

            validation = new CompareValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        ErrorMessage    = "Campaign Spot Max Ratings should be greater than or equal to 0",
                        FieldToValidate = campaignSpotMaxRatings,
                        FieldToCompare  = 0,
                        Operator        = Operator.GreaterThanEqual
                    }
                }
            };
            validation.Execute();

            validation = new CompareValidation()
            {
                Field = new List <ValidationInfo>()
                {
                    new ValidationInfo()
                    {
                        ErrorMessage    = "Campaign start date should be less than or equal to end date",
                        FieldToValidate = startDateTime,
                        FieldToCompare  = endDateTime,
                        Operator        = Operator.LessThanEqual
                    }
                }
            };
            validation.Execute();

            if (salesAreaCampaignTargets.Any())
            {
                salesAreaCampaignTargets.ForEach(s => s.Validation(s.SalesAreaGroup, s.Multiparts, s.CampaignTargets,
                                                                   startDateTime, endDateTime));
            }

            if (timeRestrictions != null && timeRestrictions.Any())
            {
                timeRestrictions.ForEach(t =>
                                         t.RequiredFieldValidation(t.StartDateTime, t.EndDateTime, t.DowPattern, t.IsIncludeOrExclude));
                timeRestrictions.ForEach(t => t.RegexValidation(t.DowPattern, t.IsIncludeOrExclude));
                timeRestrictions.ForEach(t => t.CompareValidation(t.StartDateTime, t.EndDateTime));
            }

            if (programmeRestrictions != null && programmeRestrictions.Any())
            {
                programmeRestrictions.ForEach(p =>
                                              p.RequiredFieldValidation(p.IsIncludeOrExclude, p.IsCategoryOrProgramme));
                programmeRestrictions.ForEach(p => p.RegexValidation(p.IsIncludeOrExclude, p.IsCategoryOrProgramme));
            }

            if (campaignProgrammes != null && campaignProgrammes.Any())
            {
                campaignProgrammes.ForEach(x =>
                                           x.RequiredFieldValidation(x.IsCategoryOrProgramme));
                campaignProgrammes.ForEach(p => p.RegexValidation(p.IsCategoryOrProgramme));
            }
        }