예제 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, GameLoansDbContext dbContext)
        {
            if (env.IsDevelopment() || env.IsStaging())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler(new ExceptionHandlerOptions
                {
                    ExceptionHandler = (c) =>
                    {
                        var exception  = c.Features.Get <IExceptionHandlerFeature>();
                        var statusCode = exception.Error.GetType().Name switch
                        {
                            "ArgumentException" => HttpStatusCode.BadRequest,
                            _ => HttpStatusCode.ServiceUnavailable
                        };

                        c.Response.StatusCode = (int)statusCode;
                        var content           = Encoding.UTF8.GetBytes($"Erro : [{exception.Error.Message}]");
                        c.Response.Body.WriteAsync(content, 0, content.Length);

                        return(Task.CompletedTask);
                    }
                });
                app.UseHsts();
            }

            app.UseSwagger();

            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "App Game Loans");
            });

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseCors(x => x
                        .AllowAnyOrigin()
                        .AllowAnyMethod()
                        .AllowAnyHeader());

            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
    }
 public UserRepository(GameLoansDbContext context) : base(context)
 {
 }
 public FriendRepository(GameLoansDbContext context) : base(context)
 {
 }