void SaveBankAccount(BankAccount bankAccount, Customer customer = null) { Customer cu = null; //validate bank account var validator = EntityValidatorFactory.CreateValidator(); var ba = _bankAccountRepository.Get(bankAccount.Id); if (customer != null) { cu = _customerRepository.Get(customer.Id); } if (validator.IsValid <BankAccount>(bankAccount)) // save entity { if (ba == null) { _bankAccountRepository.Add(bankAccount); } else { if (cu != null) { _customerRepository.Modify(cu); } _bankAccountRepository.Modify(ba); } _customerRepository.UnitOfWork.Commit(); _bankAccountRepository.UnitOfWork.Commit(); } else //throw validation errors { throw new ApplicationValidationErrorsException(validator.GetInvalidMessages(bankAccount)); } }
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()); }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register(Classes.FromThisAssembly(). BasedOn <ApiController>().LifestyleTransient()); container.Register(Classes.FromThisAssembly() .BasedOn <IController>() .LifestyleTransient()); container.Register( Component.For <IQueryableUnitOfWork, UnitOfWork>().ImplementedBy <UnitOfWork>().LifestylePerWebRequest(), Component.For <ILogger, TraceSourceLog>().ImplementedBy <TraceSourceLog>().LifestyleSingleton(), Component.For <IEntityTranslatorService, EntityTranslatorService>().ImplementedBy <EntityTranslatorService>().LifestyleSingleton(), Component.For <ILookupTypeRepository, LookupTypeRepository>().ImplementedBy <LookupTypeRepository>().LifestyleTransient(), Component.For <ILookupRepository, LookupRepository>().ImplementedBy <LookupRepository>().LifestyleTransient(), Component.For <ILookupViewRepository, LookupViewRepository>().ImplementedBy <LookupViewRepository>().LifestyleTransient(), Component.For <IUserRepository, UserRepository>().ImplementedBy <UserRepository>().LifestyleTransient(), Component.For <IPropertyUserRepository, PropertyUserRepository>().ImplementedBy <PropertyUserRepository>().LifestyleTransient(), Component.For <IPropertyRepository, PropertyRepository>().ImplementedBy <PropertyRepository>().LifestyleTransient(), Component.For <IPropertyFacilityRepository, PropertyFacilityRepository>().ImplementedBy <PropertyFacilityRepository>().LifestyleTransient(), Component.For <IPropertyDetailsViewRepository, PropertyDetailsViewRepository>().ImplementedBy <PropertyDetailsViewRepository>().LifestyleTransient(), Component.For <IRoomRepository, RoomRepository>().ImplementedBy <RoomRepository>().LifestyleTransient(), Component.For <IRoomFacilityRepository, RoomFacilityRepository>().ImplementedBy <RoomFacilityRepository>().LifestyleTransient(), Component.For <IRoomTariffRepository, RoomTariffRepository>().ImplementedBy <RoomTariffRepository>().LifestyleTransient(), Component.For <IRoomDetailsViewRepository, RoomDetailsViewRepository>().ImplementedBy <RoomDetailsViewRepository>().LifestyleTransient() ); //.AddFacility<LoggingFacility>(f => f.UseLog4Net()); LoggerFactory.SetCurrent(new TraceSourceLogFactory()); EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory()); IEntityTranslatorService translatorService = container.Kernel.Resolve <IEntityTranslatorService>(); RegisterTranslators(translatorService); }
void SaveProdect(GooderProudct proudct, Account account) { //recover validator var validator = EntityValidatorFactory.CreateValidator(); if (validator.IsValid(proudct)) //if customer is valid { using (TransactionScope scope = new TransactionScope()) { //add the proudct into the repository _proudctRepository.Add(proudct); account.ChangeTransactionNumber(account.TransactionNumber + 1); //commit changes _proudctRepository.UnitOfWork.Commit(); _accountRepository.UnitOfWork.Commit(); //complete transaction scope.Complete(); } } else //customer is not valid, throw validation errors { throw new ApplicationValidationErrorsException(validator.GetInvalidMessages <GooderProudct>(proudct)); } }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register(Classes.FromThisAssembly() .BasedOn <IController>() .LifestyleTransient()); container.Register( Component.For <IQueryableUnitOfWork, UnitOfWork>().ImplementedBy <UnitOfWork>(), Component.For <IProfileRepository, ProfileRepository>().ImplementedBy <ProfileRepository>(), Component.For <IAddressRepository, AddressRepository>().ImplementedBy <AddressRepository>(), Component.For <IAddressTypeRepository, AddressTypeRepository>().ImplementedBy <AddressTypeRepository>(), Component.For <IPhoneTypeRepository, PhoneTypeRepository>().ImplementedBy <PhoneTypeRepository>(), Component.For <IPhoneRepository, PhoneRepository>().ImplementedBy <PhoneRepository>(), Component.For <IProfileAddressRepository, ProfileAddressRepository>().ImplementedBy <ProfileAddressRepository>(), Component.For <IProfilePhoneRepository, ProfilePhoneRepository>().ImplementedBy <ProfilePhoneRepository>().LifestyleSingleton(), Component.For <IContactManager>().ImplementedBy <ContactManager>(), AllTypes.FromThisAssembly().BasedOn <IHttpController>().LifestyleTransient() ) .AddFacility <LoggingFacility>(f => f.UseLog4Net()); LoggerFactory.SetCurrent(new TraceSourceLogFactory()); EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory()); }
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()); }
/// <summary> /// Createt a new <paramref name="Microsoft.Samples.NLayerApp.Infrastructure.Crosscutting.Logging.ILog"/> /// </summary> /// <returns>Created ILog</returns> public static IEntityValidator CreateValidator() { if (_factory == null) { EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory()); } return((_factory != null) ? _factory.Create() : null); }
public PostsService(IPostRepository postRepository) : base(postRepository) { _postRepository = postRepository; _resources = _resources; _validator = EntityValidatorFactory.CreateValidator(); }
public void Install(IWindsorContainer container, IConfigurationStore store) { container.Register(Classes.FromThisAssembly() .BasedOn <IController>() .LifestyleTransient()); container.Register( Component.For <IQueryableUnitOfWork, UnitOfWork>().ImplementedBy <UnitOfWork>().LifeStyle.Transient, Component.For <IUserRepository, UserRepository>().ImplementedBy <UserRepository>().LifeStyle.Transient, Component.For <IFeedbackRepository, FeedbackRepository>().ImplementedBy <FeedbackRepository>().LifeStyle.Transient, Component.For <IFbDocumentRepository, FbDocumentRepository>().ImplementedBy <FbDocumentRepository>().LifeStyle.Transient, Component.For <IReservationRepository, ReservationRepository>().ImplementedBy <ReservationRepository>().LifeStyle.Transient, Component.For <INewsRepository, NewsRepository>().ImplementedBy <NewsRepository>().LifeStyle.Transient, Component.For <IArticleRepository, ArticleRepository>().ImplementedBy <ArticleRepository>().LifeStyle.Transient, Component.For <IPhotoRepository, PhotoRepository>().ImplementedBy <PhotoRepository>().LifeStyle.Transient, Component.For <IAtlasRepository, AtlasRepository>().ImplementedBy <AtlasRepository>().LifeStyle.Transient, Component.For <IBookRepository, BookRepository>().ImplementedBy <BookRepository>().LifeStyle.Transient, Component.For <IVideoRepository, AtlasRepository>().ImplementedBy <VideoRepository>().LifeStyle.Transient, Component.For <INewsCommentRepository, NewsCommentRepository>().ImplementedBy <NewsCommentRepository>().LifeStyle.Transient, Component.For <IArticleCommentRepository, ArticleCommentRepository>().ImplementedBy <ArticleCommentRepository>().LifeStyle.Transient, Component.For <IBookCommentRepository, BookCommentRepository>().ImplementedBy <BookCommentRepository>().LifeStyle.Transient, Component.For <IVideoCommentRepository, VideoCommentRepository>().ImplementedBy <VideoCommentRepository>().LifeStyle.Transient, Component.For <ISuggestionRepository, SuggestionRepository>().ImplementedBy <SuggestionRepository>().LifeStyle.Transient, Component.For <IRecentActivityRepository, RecentActivityRepository>().ImplementedBy <RecentActivityRepository>().LifeStyle.Transient, Component.For <ILogRepository, LogRepository>().ImplementedBy <LogRepository>().LifeStyle.Transient, Component.For <ILoginLogRepository, LoginLogRepository>().ImplementedBy <LoginLogRepository>().LifeStyle.Transient, Component.For <IMessageRepository, MessageRepository>().ImplementedBy <MessageRepository>().LifeStyle.Transient, Component.For <IMyMessageRepository, MyMessageRepository>().ImplementedBy <MyMessageRepository>().LifeStyle.Transient, Component.For <ITagRepository, TagRepository>().ImplementedBy <TagRepository>().LifeStyle.Transient, Component.For <IUserService>().ImplementedBy <UserService>().LifeStyle.Transient, Component.For <IFeedbackService>().ImplementedBy <FeedbackService>().LifeStyle.Transient, Component.For <IFbDocumentService>().ImplementedBy <FbDocumentService>().LifeStyle.Transient, Component.For <IReservationService>().ImplementedBy <ReservationService>().LifeStyle.Transient, Component.For <INewsService>().ImplementedBy <NewsService>().LifeStyle.Transient, Component.For <IArticleService>().ImplementedBy <ArticleService>().LifeStyle.Transient, Component.For <IPhotoService>().ImplementedBy <PhotoService>().LifeStyle.Transient, Component.For <IAtlasService>().ImplementedBy <AtlasService>().LifeStyle.Transient, Component.For <IBookService>().ImplementedBy <BookService>().LifeStyle.Transient, Component.For <IVideoService>().ImplementedBy <VideoService>().LifeStyle.Transient, Component.For <ICommentService>().ImplementedBy <CommentService>().LifeStyle.Transient, Component.For <ISuggestionService>().ImplementedBy <SuggestionService>().LifeStyle.Transient, Component.For <IRecentActivityService>().ImplementedBy <RecentActivityService>().LifeStyle.Transient, Component.For <ILoginLogService>().ImplementedBy <LoginLogService>().LifeStyle.Transient, Component.For <ILogService>().ImplementedBy <LogService>().LifeStyle.Transient, Component.For <IMessageService>().ImplementedBy <MessageService>().LifeStyle.Transient, Component.For <IMyMessageService>().ImplementedBy <MyMessageService>().LifeStyle.Transient, Component.For <ITagService>().ImplementedBy <TagService>().LifeStyle.Transient //AllTypes.FromThisAssembly().BasedOn<IHttpController>().LifestyleTransient() ).AddFacility <LoggingFacility>(f => f.UseLog4Net()); //扩张单元插件(Facilities)可以在不更改原有组件的基础上注入你所需要的功能代码, //AddFacility方法来添加扩展单元来注册并管理我们的组件。 //组件的生命周期基本上都被指定成为Transient类型,即当请求发生时创建,在处理结束后销毁。 LoggerFactory.SetCurrent(new TraceSourceLogFactory()); EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory()); }
public BlogsService(IBlogRepository blogRepository, IPostRepository postRepository) : base(blogRepository) { _blogRepository = blogRepository; _postRepository = postRepository; _resources = LocalizationFactory.CreateLocalResources(); _validator = EntityValidatorFactory.CreateValidator(); }
static void ConfigureFactories() { LoggerFactory.SetCurrent(new TraceSourceLogFactory()); EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory()); var typeAdapterFactory = _currentContainer.Resolve <ITypeAdapterFactory>(); TypeAdapterFactory.SetCurrent(typeAdapterFactory); }
private static void RegistraFabricas(IUnityContainer container) { LoggerFactory.SetCurrent(new TraceSourceLogFactory()); EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory()); var typeAdapterFactory = container.Resolve <ITypeAdapterFactory>(); TypeAdapterFactory.SetCurrent(typeAdapterFactory); }
private void ValideUsuario(Usuario usuario) { var validationManager = new ValidationManager(); var validator = EntityValidatorFactory.CreateValidator(); validationManager.AddMessages(validator.GetInvalidMessages(usuario)); validationManager.Validate(); }
private void ValideTenant(Tenant tenant) { var validationManager = new ValidationManager(); var validator = EntityValidatorFactory.CreateValidator(); validationManager.AddMessages(validator.GetInvalidMessages(tenant)); validationManager.Validate(); }
private void SalvarSocio(Socio socio) { var validator = EntityValidatorFactory.CreateValidator(); if (!validator.IsValid(socio)) { throw new AppException(validator.GetInvalidMessages <Socio>(socio)); } var specExisteSocio = SocioSpecification.ConsultaTexto(socio.Nome); if (_socioRepository.AllMatching(specExisteSocio).Any()) { throw new AppException("Já existe um sócio cadastrado com este nome."); } if (JaExisteCpf(socio.Cpf, socio.EntrevistaId, socio.Id)) { throw new AppException("Já existe um sócio cadastrado com este CPF."); } if (socio.Administrador && socio.Assina) { bool x = JaExisteAdministrador(socio.EntrevistaId); bool y = JaExisteAssinaNaReceita(socio.EntrevistaId); if (!x && y) { throw new AppException("Já existe um sócio assinando na receita."); } else if (x && !y) { throw new AppException("Já existe um sócio administrador."); } } if (socio.Administrador) { if (JaExisteAdministrador(socio.EntrevistaId)) { throw new AppException("Já existe um sócio administrador."); } } if (socio.Assina) { if (JaExisteAssinaNaReceita(socio.EntrevistaId)) { throw new AppException("Já existe um sócio assinando na receita."); } } _socioRepository.Add(socio); _socioRepository.Commit(); }
public void EntityValidatorFactory_Returns_Correct_Validator_Type() { var pev = EntityValidatorFactory<Product>.CreateEntityValidator(); Assert.IsInstanceOfType(pev, typeof(ProductEntityValidator)); var eev = EntityValidatorFactory<Employee>.CreateEntityValidator(); Assert.IsInstanceOfType(eev, typeof(EmployeeEntityValidator)); var cev = EntityValidatorFactory<Company>.CreateEntityValidator(); Assert.IsInstanceOfType(cev, typeof(CompanyEntityValidator)); }
public BaseAppService(MessageQueue messageQueue) { if (messageQueue == null) { throw new ArgumentNullException("messageQueue"); } Validator = EntityValidatorFactory.Create(); validationErrors = new List <string>(); this.messageQueue = messageQueue; }
void SalvarConfiguracaoServidorEmail(ConfiguracaoServidorEmail configuracaoServidorEmail) { var validator = EntityValidatorFactory.CreateValidator(); if (!validator.IsValid(configuracaoServidorEmail)) { throw new AppException(validator.GetInvalidMessages(configuracaoServidorEmail)); } _configuracaoServidorEmailRepository.Add(configuracaoServidorEmail); _configuracaoServidorEmailRepository.Commit(); }
static void ConfigureFactories() { try { EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory()); TypeAdapterFactory.SetCurrent(new AutomapperTypeAdapterFactory()); } catch (Exception exception) { var aramis = exception.Message; } }
/// <summary> /// Validate Entity calling IValidatableObject.Validate /// </summary> /// <param name="item">Entity to validate</param> public static void Validate <TEntity>(this TEntity item) where TEntity : class, new() { //Recover validator var validator = EntityValidatorFactory.CreateValidator(); //Validate entity if (!validator.IsValid(item)) { throw new ApplicationValidationErrorsException(validator.GetInvalidMessages(item)); } }
public static void InitializeFactories(TestContext context) { LoggerFactory.SetCurrent(new TraceSourceLogFactory()); EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory()); var dto = new CountryDTO(); // this is only to force current domain to load de .DTO assembly and all profiles var adapterfactory = new AutomapperTypeAdapterFactory(); TypeAdapterFactory.SetCurrent(adapterfactory); }
public static ExecuteResult <ValidatorResult> Validator <T>(this T val) where T : Entity { if (val == null) { new ExecuteResult <ValidatorResult>(false, "entity 为空", new ValidatorResult().SetSuccess(false).SetMessage(new string[] { "实体为空" })); } var validFactory = EntityValidatorFactory.CreateValidator(); var valid = validFactory.IsValid <T>(val); var validMsg = validFactory.GetInvalidMessages(val); return(new ExecuteResult <ValidatorResult>(valid, string.Join(";", validMsg), new ValidatorResult().SetSuccess(valid).SetMessage(validMsg))); }
private void SalvarUsoSolo(UsoSolo usoSolo) { var validator = EntityValidatorFactory.CreateValidator(); if (!validator.IsValid(usoSolo)) { throw new AppException(validator.GetInvalidMessages <UsoSolo>(usoSolo)); } _usoSoloRepository.Add(usoSolo); _usoSoloRepository.Commit(); }
private void AlterarUsoSolo(UsoSolo persistido, UsoSolo corrente) { var validator = EntityValidatorFactory.CreateValidator(); if (!validator.IsValid(corrente)) { throw new AppException(validator.GetInvalidMessages <UsoSolo>(corrente)); } _usoSoloRepository.Merge(persistido, corrente); _usoSoloRepository.Commit(); }
public static IEnumerable <string> DoIfIsValid <T>(this EntityBase entidadeASerValidada, ExecutarSeValido executarSeValido) where T : EntityBase { var validator = EntityValidatorFactory.CreateValidator(); if (validator.IsValid((T)entidadeASerValidada)) { executarSeValido(); return(null); } return(validator.GetInvalidMessages((T)entidadeASerValidada)); }
void AlterarProduto(Produto persistido, Produto corrente) { // Recupera a validação var validator = EntityValidatorFactory.CreateValidator(); if (!validator.IsValid(corrente)) { throw new ApplicationValidationErrorsException(validator.GetInvalidMessages <Produto>(corrente)); } _produtoRepository.Merge(persistido, corrente); _produtoRepository.Commit(); }
void SalvarProduto(Produto Produto) { // Validando var validator = EntityValidatorFactory.CreateValidator(); if (!validator.IsValid(Produto)) { throw new ApplicationValidationErrorsException(validator.GetInvalidMessages <Produto>(Produto)); } _produtoRepository.Add(Produto); _produtoRepository.Commit(); }
private void InitializeFactories() { EntityValidatorFactory.SetCurrent(new DataAnnotationsEntityValidatorFactory()); var dto = new BlogDTO(); // this is only to force current domain to load de .DTO assembly and all profiles var adapterfactory = new AutomapperTypeAdapterFactory(); TypeAdapterFactory.SetCurrent(adapterfactory); //Localization LocalizationFactory.SetCurrent(new ResourcesManagerFactory()); }
/// <summary> /// Save Address /// </summary> /// <param name="newAddress"></param> /// <returns></returns> private Address SaveAddress(Address address) { IEntityValidator entityValidator = EntityValidatorFactory.CreateValidator(); if (entityValidator.IsValid(address)) { _addressRepository.Add(address); _addressRepository.UnitOfWork.Commit(); return(address); } throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(address)); }
/// <summary> /// Save profile /// </summary> /// <param name="profile"></param> /// <returns></returns> private Profile SaveProfile(Profile profile) { IEntityValidator entityValidator = EntityValidatorFactory.CreateValidator(); if (entityValidator.IsValid(profile)) { _profileRepository.Add(profile); _profileRepository.UnitOfWork.Commit(); return(profile); } throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(profile)); }