// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, QuoteDbContext quoteDbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            // quoteDbContext.Database.Migrate();
            quoteDbContext.Database.EnsureCreated();
            app.UseResponseCaching();

            app.UseAuthentication();


            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
예제 #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, QuoteDbContext quoteDbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            app.UseExceptionHandler(new ExceptionHandlerOptions
            {
                ExceptionHandler = (c) =>
                {
                    var exception  = c.Features.Get <IExceptionHandlerFeature>();
                    var message    = "There has been some error";
                    var statusCode = exception.Error.GetType().Name switch
                    {
                        "ArgumentException" => HttpStatusCode.BadRequest,
                        "DbUpdateConcurrencyException" => HttpStatusCode.NotFound,
                        _ => HttpStatusCode.InternalServerError
                    };
                    switch (statusCode)
                    {
                    case HttpStatusCode.BadRequest:
                        message = "Invalid request";
                        break;

                    case HttpStatusCode.NotFound:
                        message = "No records found";
                        break;
                    }
                    c.Response.StatusCode = (int)statusCode;
                    var content           = Encoding.UTF8.GetBytes(message);
                    c.Response.Body.WriteAsync(content, 0, content.Length);
                    return(Task.CompletedTask);
                }
            });

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            quoteDbContext.Database.EnsureCreated();

            app.UseSwagger();
            app.UseSwaggerUI(swaggerUIOptions =>
            {
                swaggerUIOptions.SwaggerEndpoint("/swagger/QuoteManagement/swagger.json", "QuoteManagementApi V1");
            });
        }
    }
예제 #3
0
 public QuotesController(QuoteDbContext quoteContext)
 {
     _quoteContext = quoteContext;
 }
예제 #4
0
 public HomeController(ILogger <HomeController> logger, QuoteDbContext context, IQuoteRepository repository)
 {
     _logger     = logger;
     _context    = context;
     _repository = repository;
 }
 public HomeController(QuoteDbContext db)
 {
     _db = db;
 }
예제 #6
0
 public QuotesController(QuoteDbContext context)
 {
     _context = context;
 }
예제 #7
0
 public Repository(QuoteDbContext context)
 {
     this._context = context;
     DbSet         = this._context.Set <T>();
 }
예제 #8
0
 public CharacterService(QuoteDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
예제 #9
0
 public QuoteRepository(QuoteDbContext ctx)
 {
     _ctx = ctx;
 }
예제 #10
0
 public QuoteRepository(QuoteDbContext context) : base(context)
 {
 }
예제 #11
0
 public QuoteService(QuoteDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
예제 #12
0
 public static IQueryable <Quote> GetAllAndRelated(QuoteDbContext context)
 {
     return(context.Quotes
            .Include(q => q.ParentQuote)
            .Include(q => q.Character));
 }
예제 #13
0
 public QuoteController(ILogger <QuoteController> logger, QuoteDbContext quoteDbContext)
 {
     _quoteDbContext = quoteDbContext;
     _logger         = logger;
 }
예제 #14
0
 public HomeController(ILogger <HomeController> logger, QuoteDbContext con)
 {
     _logger = logger;
     context = con;
 }