Exemple #1
0
        public CreateFoodTruckModelV11Validator(ISocialMediaPlatformService socialMediaPlatformService)
        {
            RuleFor(f => f.Name)
            .NotEmpty().WithMessage("A food truck name must be provided")
            .Matches(FoodTruck.NAME_VALIDATION).WithMessage("The food truck name must be less than 40 characters and contain only letters, numbers, spaces");

            RuleFor(f => f.Description)
            .NotEmpty().WithMessage("The food truck must have a description")
            .Matches(FoodTruck.DESCRIPTION_VALIDATION).WithMessage("The description may only contain the following characters: letters, numbers, spaces, dash, period, comma and single quote");

            RuleFor(f => f.Website)
            .NotEmpty().WithMessage("The food truck must have a website")
            .Matches(FoodTruck.WEBSITE_VALIDATION).WithMessage("You must input a valid website url");

            RuleForEach(f => f.Tags)
            .NotNull().WithMessage("An empty tag is not allowed")
            .Matches(Tag.TAG_TEXT_REGEX).WithMessage("Tags can only contain characters and spaces");

            var socialMediaPlatforms = socialMediaPlatformService.GetAllSocialMediaPlatforms();

            RuleForEach(f => f.SocialMediaAccounts)
            .Must(sma => !String.IsNullOrWhiteSpace(sma.AccountName))
            .WithMessage("Social media account names cannot be blank or null")
            .Must(sma => socialMediaPlatforms.Any(p => p.PlatformId == sma.SocialMediaPlatformId))
            .WithMessage((model, sma) => $"No social media platform with an id of ${sma.SocialMediaPlatformId} could be found")
            .Must(sma => this.ValidateAccountNamePassesRegex(sma, socialMediaPlatforms))
            .WithMessage((model, sma) => $"No social media platform with an id of ${sma.SocialMediaPlatformId} could be found");
        }
Exemple #2
0
 public SocialMediaPlatformsController(ILogger <SocialMediaPlatformsController> logger, IMapper mapper,
                                       ISocialMediaPlatformService socialMediaPlatformService)
     : base(logger, mapper)
 {
     this._socialMediaPlatformService = socialMediaPlatformService;
 }