Exemple #1
0
        protected ProviderControllerBase(IProviderFactory <TProvider, TProviderDefinition> providerFactory, string resource, ProviderResourceMapper <TProviderResource, TProviderDefinition> resourceMapper)
        {
            _providerFactory = providerFactory;
            _resourceMapper  = resourceMapper;

            SharedValidator.RuleFor(c => c.Name).NotEmpty();
            SharedValidator.RuleFor(c => c.Name).Must((v, c) => !_providerFactory.All().Any(p => p.Name == c && p.Id != v.Id)).WithMessage("Should be unique");
            SharedValidator.RuleFor(c => c.Implementation).NotEmpty();
            SharedValidator.RuleFor(c => c.ConfigContract).NotEmpty();

            PostValidator.RuleFor(c => c.Fields).NotNull();
        }
        protected ProviderModuleBase(IProviderFactory <TProvider, TProviderDefinition> providerFactory, string resource, ProviderResourceMapper <TProviderResource, TProviderDefinition> resourceMapper)
            : base(resource)
        {
            _providerFactory = providerFactory;
            _resourceMapper  = resourceMapper;

            Get("schema", x => GetTemplates());
            Post("test", x => Test(ReadResourceFromRequest(true)));
            Post("testall", x => TestAll());
            Post("action/{action}", x => RequestAction(x.action, ReadResourceFromRequest(true, true)));

            GetResourceAll  = GetAll;
            GetResourceById = GetProviderById;
            CreateResource  = CreateProvider;
            UpdateResource  = UpdateProvider;
            DeleteResource  = DeleteProvider;

            SharedValidator.RuleFor(c => c.Name).NotEmpty();
            SharedValidator.RuleFor(c => c.Name).Must((v, c) => !_providerFactory.All().Any(p => p.Name == c && p.Id != v.Id)).WithMessage("Should be unique");
            SharedValidator.RuleFor(c => c.Implementation).NotEmpty();
            SharedValidator.RuleFor(c => c.ConfigContract).NotEmpty();

            PostValidator.RuleFor(c => c.Fields).NotNull();
        }