private void ValidateRequiredFields() { IValidation requiredFieldValidation = new RequiredFieldValidation() { Field = new List <ValidationInfo>() { new ValidationInfo() { FieldName = "Scheduled Date", FieldToValidate = ScheduledDate }, new ValidationInfo() { FieldName = "Sales Area", FieldToValidate = SalesArea }, new ValidationInfo() { FieldName = "Duration", FieldToValidate = Duration }, new ValidationInfo() { FieldName = "External Break Reference", FieldToValidate = ExternalBreakRef } } }; requiredFieldValidation.Execute(); }
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(); }
private void Validate(string salesArea, DateTime startDateTime, Duration duration, string externalReference, string programName) { IValidation validation = new RequiredFieldValidation() { Field = new List <ValidationInfo>() { new ValidationInfo() { FieldName = "Sales Area", FieldToValidate = salesArea }, new ValidationInfo() { FieldName = "Start Date Time", FieldToValidate = startDateTime }, new ValidationInfo() { FieldName = "Duration", FieldToValidate = duration }, new ValidationInfo() { FieldName = "External Reference", FieldToValidate = externalReference }, new ValidationInfo() { FieldName = "Program Name", FieldToValidate = programName } } }; validation.Execute(); }
public void Validation(SalesAreaGroup salesAreaGroup, List <MultipartModel> multiparts, List <CampaignTarget> campaignTargets, DateTime campaignStartDateTime, DateTime campaignEndDateTime) { IValidation validation = new RequiredFieldValidation() { Field = new List <ValidationInfo>() { new ValidationInfo() { FieldName = "SalesArea Group", FieldToValidate = salesAreaGroup }, new ValidationInfo() { FieldName = "Multiparts", FieldToValidate = multiparts }, new ValidationInfo() { FieldName = "Campaign Targets", FieldToValidate = campaignTargets } } }; validation.Execute(); salesAreaGroup.Validation(salesAreaGroup.GroupName, salesAreaGroup.SalesAreas); if (multiparts != null && multiparts.Any()) { multiparts.ForEach(l => l.Validation(l.Lengths)); } if (campaignTargets != null && campaignTargets.Any()) { campaignTargets.ForEach(c => c.Validation(c.StrikeWeights, campaignStartDateTime, campaignEndDateTime)); } }
} //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"); } }); } }
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(); }
public void Validation(Duration lengthValue) { IValidation validation = new RequiredFieldValidation() { Field = new List <ValidationInfo>() { new ValidationInfo() { FieldName = "Length", FieldToValidate = lengthValue }, } }; validation.Execute(); }
public void Validation(List <MultipartLength> lengths) { IValidation validation = new RequiredFieldValidation() { Field = new List <ValidationInfo>() { new ValidationInfo() { FieldName = "Multipart Lengths", FieldToValidate = lengths } } }; validation.Execute(); }
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(); }
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(); } }
private void ForgotPasswordExecute(object p) { RequiredFieldValidation requiredFieldValidation = new RequiredFieldValidation(); EmailError = requiredFieldValidation.EmailValidation(Email); if (EmailError == null) { DataService dataService = new DataService(); string userpassword = dataService.ForgotPassword(Email); if (userpassword != null) { ErrorMessage = "Your Password is: " + userpassword; } else { ErrorMessage = "Username no found"; } } }
private void ValidateChannel(string name, string shortName) { IValidation validation = new RequiredFieldValidation() { Field = new List <ValidationInfo>() { new ValidationInfo() { FieldName = "Channel Name", FieldToValidate = name }, new ValidationInfo() { FieldName = "Channel Short Name", FieldToValidate = shortName } } }; validation.Execute(); }
public static void Validate(string code, string description) { IValidation validation = new RequiredFieldValidation() { Field = new List <ValidationInfo>() { new ValidationInfo() { FieldName = "Clearance Code", FieldToValidate = code }, new ValidationInfo() { FieldName = "Clearance Description", FieldToValidate = description }, } }; validation.Execute(); }
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(); }
public void Validation(string groupName, List <string> salesAreas) { IValidation validation = new RequiredFieldValidation() { Field = new List <ValidationInfo>() { new ValidationInfo() { FieldName = "SalesArea Group Name", FieldToValidate = groupName }, new ValidationInfo() { FieldName = "SalesArea name list", FieldToValidate = salesAreas } } }; validation.Execute(); }
public void RequiredFieldValidation(string fromTime, string toTime, List <string> dowPattern) { IValidation validation = new RequiredFieldValidation() { Field = new List <ValidationInfo>() { new ValidationInfo() { FieldName = "Time Slice From Time", FieldToValidate = fromTime }, new ValidationInfo() { FieldName = "Time Slice To Time", FieldToValidate = toTime }, new ValidationInfo() { FieldName = "Dow Pattern", FieldToValidate = dowPattern } } }; validation.Execute(); }
private void LoginExecute(object parameter) { RequiredFieldValidation requiredFieldValidation = new RequiredFieldValidation(); EmailError = requiredFieldValidation.EmailValidation(Email); PasswordError = requiredFieldValidation.PasswordValidation(Password); if (EmailError == null && PasswordError == null) { ErrorMessage = string.Empty; DataService dataService = new DataService(); LoginModel login = new LoginModel { EmailId = Email, Password = Password }; LoginResponse user = dataService.GetLoginDetails(login); if (user.StatusCode == 200) { Loginauthenticated = true; TokenHandler.Token = user.token; OnLoggedIn(user.user.FirstName); ErrorMessage = "Login SuccussFull"; } else if (user.StatusCode == 404) { Loginauthenticated = false; ErrorMessage = "Username or Password is incorrect"; } else { Loginauthenticated = false; ErrorMessage = "Unable to connect to Server"; } } }
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)); } }
/// <summary> /// Validation based on restriction type and basis /// </summary> /// <param name="command"></param> private static void CustomValidation(CreateRestriction command) { IValidation validation; switch (command.RestrictionBasis) { case RestrictionBasis.Product: validation = new RequiredFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { FieldName = "Product Code", FieldToValidate = command.ProductCode } } }; validation.Execute(); validation = new EmptyFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { ErrorMessage = "Clash code must be blank/empty if basis of restriction is product", FieldToValidate = command.ClashCode }, new ValidationInfo { ErrorMessage = "Clearance code must be blank/empty if basis of restriction is product", FieldToValidate = command.ClearanceCode } } }; validation.Execute(); break; case RestrictionBasis.Clash: validation = new RequiredFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { FieldName = "Clash Code", FieldToValidate = command.ClashCode } } }; validation.Execute(); validation = new EmptyFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { ErrorMessage = "Product code must be 0 if basis of restriction is clash", FieldToValidate = command.ProductCode }, new ValidationInfo { ErrorMessage = "Clearance code must be blank/empty if basis of restriction is clash", FieldToValidate = command.ClearanceCode } } }; validation.Execute(); if (!string.IsNullOrWhiteSpace(command.ClockNumber) && (command.ClockNumber.Length > 1 || !int.TryParse(command.ClockNumber, out var clashBasedClockNumber) || clashBasedClockNumber != 0)) { throw new InvalidDataException("Clock number must be blank/empty if basis of restriction is clash"); } break; case RestrictionBasis.ClearanceCode: validation = new RequiredFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { FieldName = "Clearance Code", FieldToValidate = command.ClearanceCode } } }; validation.Execute(); validation = new EmptyFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { ErrorMessage = "Product code must be 0 if basis of restriction is clearance", FieldToValidate = command.ProductCode }, new ValidationInfo { ErrorMessage = "Clash code must be blank/empty if basis of restriction is clearance", FieldToValidate = command.ClashCode } } }; validation.Execute(); if (!string.IsNullOrWhiteSpace(command.ClockNumber) && (command.ClockNumber.Length > 1 || !int.TryParse(command.ClockNumber, out var clearanceBasedClockNumber) || clearanceBasedClockNumber != 0)) { throw new InvalidDataException("Clock number must be 0 if basis of restriction is clearance"); } break; default: throw new ArgumentOutOfRangeException(); } switch (command.RestrictionType) { case RestrictionType.Time: validation = new EmptyFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { ErrorMessage = "External programme reference must be blank/empty if restriction type is time", FieldToValidate = command.ExternalProgRef }, new ValidationInfo { ErrorMessage = "Programme category must be blank/empty if restriction type is time", FieldToValidate = command.ProgrammeCategory }, new ValidationInfo { ErrorMessage = "Programme classification must be blank/empty if restriction type is time", FieldToValidate = command.ProgrammeClassification }, new ValidationInfo { ErrorMessage = "Index type must be 0 if restriction type is time", FieldToValidate = command.IndexType }, new ValidationInfo { ErrorMessage = "Index threshold must be 0 if restriction type is time", FieldToValidate = command.IndexThreshold } } }; validation.Execute(); break; case RestrictionType.Programme: validation = new RequiredFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { FieldName = "External programme reference", FieldToValidate = command.ExternalProgRef } } }; validation.Execute(); validation = new EmptyFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { ErrorMessage = "Programme category must be blank/empty if restriction type is programme", FieldToValidate = command.ProgrammeCategory }, new ValidationInfo { ErrorMessage = "Programme classification must be blank/empty if restriction type is programme", FieldToValidate = command.ProgrammeClassification }, new ValidationInfo { ErrorMessage = "Index type must be 0 if restriction type is programme", FieldToValidate = command.IndexType }, new ValidationInfo { ErrorMessage = "Index threshold must be 0 if restriction type is programme", FieldToValidate = command.IndexThreshold } } }; validation.Execute(); break; case RestrictionType.ProgrammeCategory: validation = new RequiredFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { FieldName = "Programme category", FieldToValidate = command.ProgrammeCategory } } }; validation.Execute(); validation = new EmptyFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { ErrorMessage = "External programme reference must be blank/empty if restriction type is programme category", FieldToValidate = command.ExternalProgRef }, new ValidationInfo { ErrorMessage = "Index type must be 0 if restriction type is programme category", FieldToValidate = command.IndexType }, new ValidationInfo { ErrorMessage = "Index threshold must be 0 if restriction type is programme category", FieldToValidate = command.IndexThreshold }, new ValidationInfo { ErrorMessage = "Programme classification must be blank/empty if restriction type is programme category", FieldToValidate = command.ProgrammeClassification } } }; validation.Execute(); break; case RestrictionType.Index: validation = new RequiredFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { FieldName = "Index type", FieldToValidate = command.IndexType }, new ValidationInfo { FieldName = "Index threshold", FieldToValidate = command.IndexThreshold } } }; validation.Execute(); validation = new EmptyFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { ErrorMessage = "External programme reference must be blank/empty if restriction type is index", FieldToValidate = command.ExternalProgRef }, new ValidationInfo { ErrorMessage = "Programme category must be blank/empty if restriction type is index", FieldToValidate = command.ProgrammeCategory }, new ValidationInfo { ErrorMessage = "Programme classification must be blank/empty if restriction type is index", FieldToValidate = command.ProgrammeClassification } } }; validation.Execute(); break; case RestrictionType.ProgrammeClassification: validation = new RequiredFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { FieldName = "Programme classification", FieldToValidate = command.ProgrammeClassification } } }; validation.Execute(); validation = new EmptyFieldValidation { Field = new List <ValidationInfo> { new ValidationInfo { ErrorMessage = "External programme reference must be blank/empty if restriction type is programme classification", FieldToValidate = command.ExternalProgRef }, new ValidationInfo { ErrorMessage = "Index type must be 0 if restriction type is programme classification", FieldToValidate = command.IndexType }, new ValidationInfo { ErrorMessage = "Index threshold must be 0 if restriction type is programme classification", FieldToValidate = command.IndexThreshold }, new ValidationInfo { ErrorMessage = "Programme category must be blank/empty if restriction type is programme classification", FieldToValidate = command.ProgrammeCategory } } }; validation.Execute(); break; default: throw new ArgumentOutOfRangeException(); } }