public ElevaRepository(ElevaContext context)
 {
     _context = context;
 }
示例#2
0
 public EscolaController(ElevaContext context)
 {
     _context = context;
 }
示例#3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env,
                              ILoggerFactory loggerFactory, ElevaContext libraryContext)
        {
            loggerFactory.AddDebug(LogLevel.Information);

            if (env.IsDevelopment())
            {
                //app.UseDeveloperExceptionPage();

                app.UseExceptionHandler(appBuilder =>
                {
                    appBuilder.Run(async context =>
                    {
                        var exceptionHandlerFeature = context.Features.Get <IExceptionHandlerFeature>();
                        if (exceptionHandlerFeature != null)
                        {
                            var logger = loggerFactory.CreateLogger("Global exception logger");
                            logger.LogError(500, exceptionHandlerFeature.Error, exceptionHandlerFeature.Error.Message);
                        }
                        context.Response.StatusCode = 500;
                        await context.Response.WriteAsync(
                            "Uma falha inesperada aconteceu. Tente novamente mais tarde.");
                    });
                });
            }
            else
            {
                app.UseExceptionHandler(appBuilder =>
                {
                    appBuilder.Run(async context =>
                    {
                        context.Response.StatusCode = 500;
                        await context.Response.WriteAsync(
                            "Uma falha inesperada aconteceu. Tente novamente mais tarde.");
                    });
                });
            }

            AutoMapper.Mapper
            .Initialize(cfg => {
                //Escola

                cfg.CreateMap <Escola, EscolaDto>();

                cfg.CreateMap <EscolaForCreationDto, Escola>();

                cfg.CreateMap <EscolaForUpdateDto, Escola>();

                cfg.CreateMap <EscolaForUpdateDto, TurmaForUpdateDto>();

                // Turma

                cfg.CreateMap <Turma, TurmaDto>()
                .ForMember(dest => dest.NomeCompleto,
                           opt => opt.MapFrom(src => $"{src.Ano}º do {src.Etapa} - {src.Numero}"));

                cfg.CreateMap <TurmaForCreationDto, Turma>();

                cfg.CreateMap <TurmaForUpdateDto, Turma>();

                cfg.CreateMap <Turma, TurmaForUpdateDto>();
            });

            libraryContext.EnsureSeedDataForContext();

            //Code Responsible for allowing requests from the same origin
            app.UseCors("AllowAllHeaders");
            app.UseMvc();
        }