Exemplo n.º 1
0
        internal Order CreateOrderFromCart(ShoppingCart cart,
                                           Customer customer,
                                           string customerRemarks,
                                           string billingAccount,
                                           IEntityValidator <Order> orderValidator,
                                           Address optionalShippingAddress = null,
                                           Address optionalBillingAddress  = null)
        {
            var order           = new Order();
            var shippingAddress = optionalShippingAddress ?? customer.Address;
            var billingAddress  = optionalBillingAddress ?? customer.Address;

            order.BillingAccount  = billingAccount;
            order.BillingAddress  = billingAddress;
            order.CustomerRemarks = customerRemarks;
            order.ShippingAddress = shippingAddress;
            order.VAT             = customer?.Address?.Country?.VATPercentage ?? 0;

            order.OrderLines = new List <OrderLine>(ConvertFromCartItems(cart.ShoppingCartItems));

            order.UpdateTotalsAndVAT();

            orderValidator.Validate(order);

            return(order);
        }
Exemplo n.º 2
0
 public TaskService(ITaskAggregate taskAggregate, ITaskRepository taskRepository, IEntityValidator entityValidator, ICurrentUserService currentUserService)
 {
     _taskAggregate      = taskAggregate;
     _taskRepository     = taskRepository;
     _entityValidator    = entityValidator;
     _currentUserService = currentUserService;
 }
Exemplo n.º 3
0
        public void PerformValidationIsValidReturnTrueWithValidEntities()
        {
            //Arrange
            var entityA = new EntityWithValidationAttribute();

            entityA.RequiredProperty = "the data";

            var entityB = new EntityWithValidatableObject();

            entityB.RequiredProperty = "the data";

            IEntityValidator entityValidator = EntityValidatorFactory.CreateValidator();

            //Act
            var entityAValidationResult = entityValidator.IsValid(entityA);
            var entityAInvalidMessages  = entityValidator.GetInvalidMessages(entityA);
            var entityBValidationResult = entityValidator.IsValid(entityB);
            var entityBInvalidMessages  = entityValidator.GetInvalidMessages(entityB);

            //Assert
            Assert.True(entityAValidationResult);
            Assert.True(entityBValidationResult);
            Assert.False(entityAInvalidMessages.Any());
            Assert.False(entityBInvalidMessages.Any());
        }
Exemplo n.º 4
0
        protected override void Context()
        {
            _createIndvidualAlgorithm             = A.Fake <ICreateIndividualAlgorithm>();
            _entityBaseFactory                    = A.Fake <IObjectBaseFactory>();
            _individualModelTask                  = A.Fake <IIndividualModelTask>();
            _speciesRepository                    = A.Fake <ISpeciesRepository>();
            _entityValidator                      = A.Fake <IEntityValidator>();
            _reportGenerator                      = A.Fake <IReportGenerator>();
            _genderRepository                     = A.Fake <IGenderRepository>();
            _moleculeOntogenyVariabilityUpdater   = A.Fake <IMoleculeOntogenyVariabilityUpdater>();
            _diseaseStateImplementationRepository = A.Fake <IDiseaseStateImplementationFactory>();

            sut = new IndividualFactory(
                _individualModelTask,
                _entityBaseFactory,
                _createIndvidualAlgorithm,
                _speciesRepository,
                _entityValidator,
                _reportGenerator,
                _moleculeOntogenyVariabilityUpdater,
                _genderRepository,
                _diseaseStateImplementationRepository
                );

            _age            = DomainHelperForSpecs.ConstantParameterWithValue().WithName(CoreConstants.Parameters.AGE);
            _gestationalAge = DomainHelperForSpecs.ConstantParameterWithValue().WithName(Constants.Parameters.GESTATIONAL_AGE);
            _height         = DomainHelperForSpecs.ConstantParameterWithValue().WithName(CoreConstants.Parameters.HEIGHT);
            _weight         = DomainHelperForSpecs.ConstantParameterWithValue().WithName(CoreConstants.Parameters.WEIGHT);
            _bmi            = DomainHelperForSpecs.ConstantParameterWithValue().WithName(CoreConstants.Parameters.BMI);
        }
Exemplo n.º 5
0
 public CommentaryDomainService(
     IRepository <CommentaryIndexDriverEntity> commentaryIndexDriverRepository,
     IEntityValidator <CommentaryIndexDriverEntity> commentaryIndexDriverEntityValidator,
     IRepository <CommentaryIndexTeamEntity> commentaryIndexTeamRepository,
     IEntityValidator <CommentaryIndexTeamEntity> commentaryIndexTeamEntityValidator,
     IRepository <CommentaryPrefixDriverEntity> commentaryPrefixDriverRepository,
     IEntityValidator <CommentaryPrefixDriverEntity> commentaryPrefixDriverEntityValidator,
     IRepository <CommentaryPrefixTeamEntity> commentaryPrefixTeamRepository,
     IEntityValidator <CommentaryPrefixTeamEntity> commentaryPrefixTeamEntityValidator,
     IRepository <CommentaryDriverEntity> commentaryDriverRepository,
     IEntityValidator <CommentaryDriverEntity> commentaryDriverEntityValidator,
     IRepository <CommentaryTeamEntity> commentaryTeamRepository,
     IEntityValidator <CommentaryTeamEntity> commentaryTeamEntityValidator,
     CommentaryFileDirectoryListingService commentaryFileDirectoryListingService)
 {
     _commentaryIndexDriverRepository       = commentaryIndexDriverRepository ?? throw new ArgumentNullException(nameof(commentaryIndexDriverRepository));
     _commentaryIndexDriverEntityValidator  = commentaryIndexDriverEntityValidator ?? throw new ArgumentNullException(nameof(commentaryIndexDriverEntityValidator));
     _commentaryIndexTeamRepository         = commentaryIndexTeamRepository ?? throw new ArgumentNullException(nameof(commentaryIndexTeamRepository));
     _commentaryIndexTeamEntityValidator    = commentaryIndexTeamEntityValidator ?? throw new ArgumentNullException(nameof(commentaryIndexTeamEntityValidator));
     _commentaryPrefixDriverRepository      = commentaryPrefixDriverRepository ?? throw new ArgumentNullException(nameof(commentaryPrefixDriverRepository));
     _commentaryPrefixDriverEntityValidator = commentaryPrefixDriverEntityValidator ?? throw new ArgumentNullException(nameof(commentaryPrefixDriverEntityValidator));
     _commentaryPrefixTeamRepository        = commentaryPrefixTeamRepository ?? throw new ArgumentNullException(nameof(commentaryPrefixTeamRepository));
     _commentaryPrefixTeamEntityValidator   = commentaryPrefixTeamEntityValidator ?? throw new ArgumentNullException(nameof(commentaryPrefixTeamEntityValidator));
     _commentaryDriverRepository            = commentaryDriverRepository ?? throw new ArgumentNullException(nameof(commentaryDriverRepository));
     _commentaryDriverEntityValidator       = commentaryDriverEntityValidator ?? throw new ArgumentNullException(nameof(commentaryDriverEntityValidator));
     _commentaryTeamRepository              = commentaryTeamRepository ?? throw new ArgumentNullException(nameof(commentaryTeamRepository));
     _commentaryTeamEntityValidator         = commentaryTeamEntityValidator ?? throw new ArgumentNullException(nameof(commentaryTeamEntityValidator));
     _commentaryFileDirectoryListingService = commentaryFileDirectoryListingService ?? throw new ArgumentNullException(nameof(commentaryFileDirectoryListingService));
 }
Exemplo n.º 6
0
 protected UserStorageService(IEntityValidator <User> _validator = null, IIdGenerator _generator = null, params User[] users) // : this(_validator, _generator)
 {
     foreach (User u in users)
     {
         this.Add(u);
     }
 }
Exemplo n.º 7
0
 public LoanCommandHandler(LenderContext context, NotificationContext notification, IEntityValidator entityValidator, IMapper mapper)
 {
     _context         = context;
     _notification    = notification;
     _entityValidator = entityValidator;
     _mapper          = mapper;
 }
Exemplo n.º 8
0
 protected UserStorageService(IEnumerable <User> users, IEntityValidator <User> _validator = null, IIdGenerator _generator = null) : this(_validator, _generator)
 {
     foreach (User u in users)
     {
         this.Add(u);
     }
 }
 public FriendshipService(
     IUnitOfWork unitOfWork, 
     IEntityValidator<User> userValidator)
     : base(unitOfWork)
 {
     this._userValidator = userValidator;
 }
Exemplo n.º 10
0
 public LanguageDomainService(
     IRepository <LanguageEntity> languageRepository,
     IEntityValidator <LanguageEntity> languageEntityValidator)
 {
     _languageRepository      = languageRepository ?? throw new ArgumentNullException(nameof(languageRepository));
     _languageEntityValidator = languageEntityValidator ?? throw new ArgumentNullException(nameof(languageEntityValidator));
 }
Exemplo n.º 11
0
 public TrackDomainService(
     IRepository <TrackEntity> trackRepository,
     IEntityValidator <TrackEntity> trackEntityValidator)
 {
     _trackRepository      = trackRepository ?? throw new ArgumentNullException(nameof(trackRepository));
     _trackEntityValidator = trackEntityValidator ?? throw new ArgumentNullException(nameof(trackEntityValidator));
 }
Exemplo n.º 12
0
 public PerformanceCurveDomainService(
     IRepository <PerformanceCurveEntity> performanceCurveRepository,
     IEntityValidator <PerformanceCurveEntity> performanceCurveEntityValidator)
 {
     _performanceCurveRepository      = performanceCurveRepository ?? throw new ArgumentNullException(nameof(performanceCurveRepository));
     _performanceCurveEntityValidator = performanceCurveEntityValidator ?? throw new ArgumentNullException(nameof(performanceCurveEntityValidator));
 }
Exemplo n.º 13
0
        public void RegisterValidatorAndRetrieve()
        {
            IIocContainer iocContainer = Substitute.For <IIocContainer>();
            IocContainerValidatorFactory iocContainerValidatorFactory = new IocContainerValidatorFactory(iocContainer);
            CustomerValidator            customerValidator            = new CustomerValidator();

            Dictionary <string, IEntityValidator <Customer> > registry = new Dictionary <string, IEntityValidator <Customer> >();

            iocContainer.WhenForAnyArgs(x => x.RegisterSingleInstanceNamed <IEntityValidator <Customer> >(null, null)).Do(x =>
            {
                Func <IIocContainerResolver, IEntityValidator <Customer> > func = x.Arg <Func <IIocContainerResolver, IEntityValidator <Customer> > >();
                string name = x.Arg <string>();

                IEntityValidator <Customer> validator = func(iocContainer);

                registry.Add(name, validator);
            });

            iocContainer.GetInstanceOptionalByName(null, null).ReturnsForAnyArgs(x =>
            {
                string name = x.Arg <string>();

                return(registry[name]);
            });

            iocContainerValidatorFactory.RegisterValidator(customerValidator);
            IEntityValidator <Customer> entityValidator = iocContainerValidatorFactory.GetValidatorFor <Customer>();

            Assert.IsNotNull(entityValidator);
            Assert.AreSame(customerValidator, entityValidator);
        }
Exemplo n.º 14
0
 protected override void Context()
 {
     _executionContext      = A.Fake <IOSPSuiteExecutionContext>();
     _entityValidator       = A.Fake <IEntityValidator>();
     _applicationController = A.Fake <IApplicationController>();
     sut = new EntityValidationTask(_entityValidator, _applicationController, _executionContext);
 }
Exemplo n.º 15
0
 public AmigoService(EmprestimosContext context, NotificationContext notification, IEntityValidator entityValidator, IMapper mapper)
 {
     _context         = context;
     _notification    = notification;
     _entityValidator = entityValidator;
     _mapper          = mapper;
 }
Exemplo n.º 16
0
 public DynamoDbSet(
     IIndexExtractor indexExtractor,
     ITableNameExtractor tableNameExtractor,
     IPrimaryKeyExtractor primaryKeyExtractor,
     IEntityValidator validator,
     IDynamoContextOptionsProvider optionsProvider,
     IEntityConfigurationProvider entityConfigurationProvider,
     Type contextType)
 {
     this.contextOptions      = optionsProvider.GetContextOptions(contextType);
     this.Client              = this.contextOptions.AwsOptions.CreateServiceClient <IAmazonDynamoDB>();
     this.Base                = new DynamoDBContext(this.Client);
     this.indexExtractor      = indexExtractor;
     this.tableNameExtractor  = tableNameExtractor;
     this.primaryKeyExtractor = primaryKeyExtractor;
     this.validator           = validator;
     this.table               = this.Base.TryGetTargetTable <TEntity>(this.operationConfig);
     this.entityConfig        = entityConfigurationProvider.GetEntityConfiguration(
         this.contextOptions.ContextType, typeof(TEntity)) as IEntityConfiguration <TEntity>;
     this.operationConfig = new DynamoDBOperationConfig
     {
         OverrideTableName = this.tableNameExtractor.ExtractTableName(
             this.contextOptions, this.entityConfig, this.table),
         Conversion = this.contextOptions.Conversion ?? DynamoDBEntryConversion.V1
     };
 }
Exemplo n.º 17
0
 public DataUpdater(
     IAppContext appContext
     , IEntityFinder entityFinder
     , IRoleObjectAccessEntityPermissionService roleObjectAccessEntityPermissionService
     , IPrincipalObjectAccessService principalObjectAccessService
     , IEventPublisher eventPublisher
     , IBusinessUnitService businessUnitService
     , IOrganizationDataProvider organizationDataProvider
     , IOrganizationDataRetriever organizationDataRetriever
     , IAttributeFinder attributeFinder
     , IEntityPluginExecutor entityPluginExecutor
     , IDataAssigner dataAssigner
     , IMapUpdater mapUpdater
     , IFormulaUpdater formulaUpdater
     , IQueryResolverFactory queryResolverFactory
     , IEntityValidator entityValidator
     )
     : base(appContext, entityFinder, roleObjectAccessEntityPermissionService, principalObjectAccessService, eventPublisher, businessUnitService)
 {
     _organizationDataProvider  = organizationDataProvider;
     _organizationDataRetriever = organizationDataRetriever;
     _attributeFinder           = attributeFinder;
     _entityPluginExecutor      = entityPluginExecutor;
     _dataAssigner         = dataAssigner;
     _mapUpdater           = mapUpdater;
     _formulaUpdater       = formulaUpdater;
     _queryResolverFactory = queryResolverFactory;
     _entityValidator      = entityValidator;
 }
Exemplo n.º 18
0
        public void TestMethod1()
        {
            //Arrange
            var entityA = new EntityWithValidationAttribute();

            entityA.RequiredProperty = null;

            var entityB = new EntityWithValidatableObject();

            entityB.RequiredProperty = null;

            IEntityValidator entityValidator = EntityValidatorFactory.CreateValidator();

            //Act
            var entityAValidationResult = entityValidator.IsValid(entityA);
            var entityAInvalidMessages  = entityValidator.GetInvalidMessages(entityA);

            var entityBValidationResult = entityValidator.IsValid(entityB);
            var entityBInvalidMessages  = entityValidator.GetInvalidMessages(entityB);

            //Assert
            Assert.IsFalse(entityAValidationResult);
            Assert.IsFalse(entityBValidationResult);

            Assert.IsTrue(entityAInvalidMessages.Any());
            Assert.IsTrue(entityBInvalidMessages.Any());
        }
Exemplo n.º 19
0
        protected virtual List <string> ValidateGraph(IEntity entity)
        {
            if (entity.ObjectState != ObjectState.Added && entity.ObjectState != ObjectState.Modified)
            {
                return(new List <string>());
            }
            List <string>    stringList      = new List <string>();
            IEntityValidator entityValidator = ValidationManager.GetEntityValidator(entity.GetType());

            stringList.AddRange((IEnumerable <string>) this.Validate(entityValidator, (IObjectState)entity));
            foreach (PropertyInfo property in entity.GetType().GetProperties())
            {
                if (!((IEnumerable <ParameterInfo>)property.GetIndexParameters()).Any <ParameterInfo>())
                {
                    object obj = property.GetValue((object)entity, (object[])null);
                    if (obj is IEntity)
                    {
                        stringList.AddRange((IEnumerable <string>) this.ValidateGraph(obj as IEntity));
                    }
                    else if (obj is IEnumerable <IEntity> )
                    {
                        foreach (IEntity entity1 in property.GetValue((object)entity, (object[])null) as IEnumerable <IEntity> )
                        {
                            stringList.AddRange((IEnumerable <string>) this.ValidateGraph(entity1));
                        }
                    }
                }
            }
            return(stringList);
        }
Exemplo n.º 20
0
        public PostsService(IPostRepository postRepository)
            : base(postRepository)
        {
            _postRepository = postRepository;

            _resources = _resources;
            _validator = EntityValidatorFactory.CreateValidator();
        }
 public MessageService(
     IUnitOfWork unitOfWork,
     IEntityValidator<Message> messageValidator,
     IEntityValidator<User> userValidator) : base(unitOfWork)
 {
     this._messageValidator = messageValidator;
     this._userValidator = userValidator;
 }
Exemplo n.º 22
0
 public void AddInsertValidator <T>(IEntityValidator <T> validator) where T : class
 {
     if (InsertValidators.ContainsKey(typeof(T)))
     {
         throw new Exception("Insert Validator for given type already exists");
     }
     InsertValidators.Add(typeof(T), validator);
 }
 /// <inheritdoc />
 protected EntityManager(
     IMapper mapper,
     IViewModelFactory <TEntity, TCreateViewModel, TUpdateViewModel> viewModelFactory,
     IEntityValidator <TEntity> validator)
 {
     CurrentMapper    = mapper;
     ViewModelFactory = viewModelFactory;
     Validator        = validator;
 }
        /// <summary>
        /// Registers the validator.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="validator">The validator.</param>
        public void RegisterValidator <TEntity>(IEntityValidator <TEntity> validator)
        {
            if (validator == null)
            {
                throw new ArgumentNullException("validator");
            }

            m_IocContainer.RegisterSingleInstanceNamed(x => validator, typeof(TEntity).FullName);
        }
Exemplo n.º 25
0
        public BlogsService(IBlogRepository blogRepository, IPostRepository postRepository)
            : base(blogRepository)
        {
            _blogRepository = blogRepository;
            _postRepository = postRepository;

            _resources = LocalizationFactory.CreateLocalResources();
            _validator = EntityValidatorFactory.CreateValidator();
        }
Exemplo n.º 26
0
        public CaregiverEditView(int CaregiverId)
        {
            InitializeComponent();
            _caregiverEditViewModel = Program.Factory.Resolve <CaregiverEditViewModel>();

            _CaregiverEntityValidator = Program.Factory.Resolve <IEntityValidator>();

            LoadCaregiver(CaregiverId);
        }
Exemplo n.º 27
0
 public TeamDomainService(
     IRepository <TeamEntity> teamRepository,
     IEntityValidator <TeamEntity> teamEntityValidator,
     RandomService randomService)
 {
     _teamRepository      = teamRepository ?? throw new ArgumentNullException(nameof(teamRepository));
     _teamEntityValidator = teamEntityValidator ?? throw new ArgumentNullException(nameof(teamEntityValidator));
     _randomService       = randomService ?? throw new ArgumentNullException(nameof(randomService));
 }
        /// <summary>
        /// Registers the validator.
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity.</typeparam>
        /// <param name="validator">The validator.</param>
        public void RegisterValidator <TEntity>(IEntityValidator <TEntity> validator)
        {
            if (validator == null)
            {
                throw new ArgumentNullException("validator");
            }

            m_Validators.Add(typeof(TEntity).FullName, validator);
        }
Exemplo n.º 29
0
 public EfCoreEntityHandlerInternal(
     IImplementationsContainer implementationsContainer,
     IEntityValidator validator,
     EntityHelper entityHelper)
 {
     _implementationsContainer = implementationsContainer;
     _validator    = validator;
     _entityHelper = entityHelper;
 }
Exemplo n.º 30
0
 public IntegrationService(IRepository <Integration, SearchQueryIntegration> repository,
                           IEntityValidator <Integration, int?> validator,
                           IPublisher <IIntegrationDeleted> integrationDeletePublisher,
                           ICustomerIdService customerIdService)
 {
     _repository = repository;
     _validator  = validator;
     _integrationDeletePublisher = integrationDeletePublisher;
     _customerIdService          = customerIdService;
 }
Exemplo n.º 31
0
 public UsersController(
     IMapper mapper,
     IUserRepository <User> repo,
     IEntityValidator <UserDto> validator
     )
 {
     _repo      = repo;
     _validator = validator;
     _mapper    = mapper;
 }
Exemplo n.º 32
0
        public FamilyEditView(int FatherID)
        {
            InitializeComponent();

            _fatherEditViewModel = Program.Factory.Resolve <FamilyEditViewModel>();

            _familyEntityValidator = Program.Factory.Resolve <IEntityValidator>();

            LoadFamily(FatherID);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="LaboModelValidator"/> class.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        /// <param name="controllerContext">The controller context.</param>
        /// <param name="validator">The validator.</param>
        /// <param name="validationTransformer">The validation transformer.</param>
        /// <exception cref="System.ArgumentNullException">validator</exception>
        public LaboModelValidator(ModelMetadata metadata, ControllerContext controllerContext, IEntityValidator validator, IValidationTransformer validationTransformer = null)
            : base(metadata, controllerContext)
        {
            if (validator == null)
            {
                throw new ArgumentNullException("validator");
            }

            m_Validator = validator;
            m_ValidationTransformer = validationTransformer;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="CommentService"/> class.
 /// </summary>
 /// <param name="unitOfWork">
 /// The unit of work.
 /// </param>
 /// <param name="commentValidator">
 /// The comment validator.
 /// </param>
 /// <param name="imageValidator">
 /// The image validator.
 /// </param>
 /// <param name="userValidator">
 /// The user validator.
 /// </param>
 public CommentService(
     IUnitOfWork unitOfWork, 
     IEntityValidator<Comment> commentValidator, 
     IEntityValidator<Image> imageValidator, 
     IEntityValidator<User> userValidator)
     : base(unitOfWork)
 {
     this._commentValidator = commentValidator;
     this._imageValidator = imageValidator;
     this._userValidator = userValidator;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ImageAlbumService"/> class.
 /// </summary>
 /// <param name="unitOfWork">
 /// The unit of work.
 /// </param>
 /// <param name="userValidator">
 /// The user validator.
 /// </param>
 /// <param name="albumValidator">
 /// The album validator.
 /// </param>
 /// <param name="imageValidator">
 /// The image validator.
 /// </param>
 /// <param name="imageResizingService">
 /// The image resizing service.
 /// </param>
 public ImageAlbumService(
     IUnitOfWork unitOfWork, 
     IEntityValidator<User> userValidator, 
     IEntityValidator<Album> albumValidator, 
     IEntityValidator<Image> imageValidator, 
     IImageResizingService imageResizingService)
     : base(unitOfWork)
 {
     this._userValidator = userValidator;
     this._albumValidator = albumValidator;
     this._imageValidator = imageValidator;
     this._imageResizingService = imageResizingService;
 }
 /// <summary>
 /// Gets the validators for model.
 /// </summary>
 /// <param name="metadata">The metadata.</param>
 /// <param name="context">The context.</param>
 /// <param name="validator">The validator.</param>
 /// <param name="validationTransformer">The validation transformer.</param>
 /// <returns>The model validators.</returns>
 private static IEnumerable<ModelValidator> GetValidatorsForModel(ModelMetadata metadata, ControllerContext context, IEntityValidator validator, IValidationTransformer validationTransformer)
 {
     if (validator != null)
     {
         yield return new LaboModelValidator(metadata, context, validator, validationTransformer);
     }
 }
Exemplo n.º 37
0
 public bool Validate(IEntityValidator<EntityBase> validator)
 {
     return validator.IsValid(this);
 }
Exemplo n.º 38
0
 public DataErrorInfoBehavior(IEntityValidator entityValidator)
 {
     _entityValidator = entityValidator;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SubscriptionService"/> class.
 /// </summary>
 /// <param name="unitOfWork">
 /// The unit of work.
 /// </param>
 /// <param name="userValidator">
 /// The user validator.
 /// </param>
 public SubscriptionService(IUnitOfWork unitOfWork, IEntityValidator<User> userValidator)
     : base(unitOfWork)
 {
     this._userValidator = userValidator;
 }
        /// <summary>
        /// Gets the validators for property.
        /// </summary>
        /// <param name="metadata">The metadata.</param>
        /// <param name="context">The context.</param>
        /// <param name="validator">The validator.</param>
        /// <param name="validationTransformer">The validation transformer.</param>
        /// <returns>The validators.</returns>
        private IEnumerable<ModelValidator> GetValidatorsForProperty(ModelMetadata metadata, ControllerContext context, IEntityValidator validator, IValidationTransformer validationTransformer)
        {
            List<ModelValidator> modelValidators = new List<ModelValidator>();

            if (validator != null)
            {
                IList<IEntityValidationRule> validationRules = validator.ValidationRules;

                HashSet<string> requiredPropertyValidators = new HashSet<string>(StringComparer.OrdinalIgnoreCase); 

                for (int i = 0; i < validationRules.Count; i++)
                {
                    IEntityValidationRule entityValidationRule = validationRules[i];

                    string propertyName = ValidationTransformerHelper.GetPropertyName(metadata, validationTransformer);
                    if (entityValidationRule.MemberInfo.Name == propertyName)
                    {
                        ModelValidator modelValidator = GetModelPropertyValidator(metadata, context, entityValidationRule);
                        if (modelValidator != null)
                        {
                            if (modelValidator.IsRequired)
                            {
                                // There can be one required validator per property
                                if (!requiredPropertyValidators.Contains(propertyName))
                                {
                                    requiredPropertyValidators.Add(propertyName);
                                    modelValidators.Add(modelValidator); 
                                }
                            }
                            else
                            {
                                modelValidators.Add(modelValidator);                                
                            }
                        }
                    }
                }

                if (metadata.IsRequired && AddImplicitRequiredAttributeForValueTypes)
                {
                    bool hasRequiredValidators = modelValidators.Any(x => x.IsRequired);

                    if (!hasRequiredValidators)
                    {
                        modelValidators.Add(CreateNotNullValidatorForProperty(metadata, context));
                    }
                }
            }

            return modelValidators;
        }
Exemplo n.º 41
0
 public WareGroupModel(IDao<WareGroup> workerDao, IEntityFactory entityFactory, IEntityValidator validator)
 {
     _wareGroupDao = workerDao;
     _entityFactory = entityFactory;
     _validator = validator;
 }
Exemplo n.º 42
0
 public ValidationCallHandler(IEntityValidator validator)
 {
     this.validator = validator;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="MembershipService"/> class.
        /// </summary>
        /// <param name="unitOfWork">
        /// The unit of work.
        /// </param>
        /// <param name="userValidator">
        /// The user validator.
        /// </param>
        /// <param name="roleValidator">
        /// The role validator.
        /// </param>
        /// <param name="profileValidator">
        /// The profile validator.
        /// </param>
        /// <param name="accessRightValidator">
        /// The access right validator.
        /// </param>
        /// <param name="hashGenerator">
        /// The hash generator.
        /// </param>
        public MembershipService(
            IUnitOfWork unitOfWork, 
            IEntityValidator<User> userValidator, 
            IEntityValidator<Role> roleValidator, 
            IEntityValidator<Profile> profileValidator, 
            IHashGenerator hashGenerator)
            : base(unitOfWork)
        {
            this._userValidator = userValidator;
            this._roleValidator = roleValidator;
            this._profileValidator = profileValidator;
            this._hashGenerator = hashGenerator;

            this._userRepository = this.UnitOfWork.Repository<User, int>() as IUserRepository;
            this._profileRepository =
                this.UnitOfWork.Repository<Profile, int>() as IProfileRepository;
            this._roleRepository = this.UnitOfWork.Repository<Role, int>();
        }