예제 #1
0
        public async Task <IEnumerable <ValidationResult> > ValidateAsync(ValidationContext validationContext)
        {
            List <ValidationResult> results = new List <ValidationResult>();

            var carWorkshopsRepository = (ICarWorkshopsRepository)validationContext.GetService(typeof(ICarWorkshopsRepository));
            var carWorkshopModels      = await carWorkshopsRepository.FindByConditionAsync(o => ModelsUtils.GetIsValueUnique(this, o, CompanyName.ToLower(), o.CompanyName.ToLower()));

            if (carWorkshopModels.Any())
            {
                results.Add(new ValidationResult(ModelsMessages.GetModelFieldUniqueError(CompanyName), new[] { nameof(CompanyName) }));
            }

            return(results);
        }
예제 #2
0
        public async Task <IEnumerable <ValidationResult> > ValidateAsync(ValidationContext validationContext)
        {
            List <ValidationResult> results = new List <ValidationResult>();

            var usersRepository = (IUsersRepository)validationContext.GetService(typeof(IUsersRepository));
            var userModels      = await usersRepository.FindByConditionAsync(o => ModelsUtils.GetIsValueUnique(this, o, Username.ToLower(), o.Username.ToLower()));

            if (userModels.Any())
            {
                results.Add(new ValidationResult(ModelsMessages.GetModelFieldUniqueError(Username), new[] { nameof(Username) }));
            }

            userModels = await usersRepository.FindByConditionAsync(o => ModelsUtils.GetIsValueUnique(this, o, Email.ToLower(), o.Email.ToLower()));

            if (userModels.Any())
            {
                results.Add(new ValidationResult(ModelsMessages.GetModelFieldUniqueError(Email), new[] { nameof(Email) }));
            }

            return(results);
        }