Ejemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ICheckDbService check)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseAuthentication();


            app.UseMiddleware <LoggingMiddleware>();

            app.Use(async(context, next) =>
            {
                if (!context.Request.Headers.ContainsKey("Index"))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Nie podano indeksu w nagłówku");
                    return;
                }
                var index = context.Request.Headers["Index"].ToString();

                if (!check.check(index))
                {
                    context.Response.StatusCode = StatusCodes.Status401Unauthorized;
                    await context.Response.WriteAsync("Błędny indeks");
                    return;
                }


                await next();
            });

            app.UseMvc();
        }
Ejemplo n.º 2
0
 public GetProductByIdQueryValidation(
     ICheckDbService checkDbService)
 {
     _checkDbService = checkDbService;
     RuleFor(x => x.ProductId)
     .NotNull()
     .GreaterThan(0)
     .MustAsync(_checkDbService.CheckProductIdAsync)
     .WithMessage("Product ID is not valid !");
 }
Ejemplo n.º 3
0
        public GetCategoryByIdQueryValidation(
            ICheckDbService checkDbService)
        {
            _checkDbService = checkDbService;

            RuleFor(x => x.CategoryId)
            .NotNull()
            .GreaterThan(0)
            .MustAsync(checkDbService.CheckCategoryIdAsync)
            .WithMessage("Category ID is not valid!");
        }