// 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, HartPRContext hartPRContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { 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("An unexpected fault happened. Try again later."); }); }); } AutoMapper.Mapper.Initialize(cfg => { // players mapping cfg.CreateMap <Entities.Player, Models.PlayerDto>() .ForMember(dest => dest.Name, opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}")); //cfg.CreateMap<Entities.Player, Models.PlayerMeleeDto>() // .ForMember(dest => dest.Name, opt => opt.MapFrom(src => // $"{src.FirstName} {src.LastName}")) // .ForMember(dest => dest.Trueskill, opt => opt.MapFrom(src => // src.MeleeTrueskill)); //cfg.CreateMap<Entities.Player, Models.PlayerSmash4Dto>() // .ForMember(dest => dest.Name, opt => opt.MapFrom(src => // $"{src.FirstName} {src.LastName}")) // .ForMember(dest => dest.Trueskill, opt => opt.MapFrom(src => // src.Smash4Trueskill)); //cfg.CreateMap<Entities.Player, Models.PlayerPMDto>() // .ForMember(dest => dest.Name, opt => opt.MapFrom(src => // $"{src.FirstName} {src.LastName}")) // .ForMember(dest => dest.Trueskill, opt => opt.MapFrom(src => // src.PMTrueskill)); cfg.CreateMap <Models.PlayerDto, Entities.Player>(); //cfg.CreateMap<Models.PlayerMeleeDto, Entities.Player>(); //cfg.CreateMap<Models.PlayerSmash4Dto, Entities.Player>(); //cfg.CreateMap<Models.PlayerPMDto, Entities.Player>(); //cfg.CreateMap<Models.AuthorForCreationWithDateOfDeathDto, Entities.Author>(); cfg.CreateMap <Models.PlayerForCreationDto, Entities.Player>(); cfg.CreateMap <Models.PlayerForManipulationDto, Entities.Player>(); cfg.CreateMap <Models.PlayerForUpdateDto, Entities.Player>(); cfg.CreateMap <Entities.Player, Models.PlayerForUpdateDto>(); // tournaments mapping cfg.CreateMap <Entities.Tournament, Models.TournamentDto>(); cfg.CreateMap <Models.TournamentDto, Entities.Tournament>(); cfg.CreateMap <Models.TournamentForCreationDto, Entities.Tournament>(); cfg.CreateMap <Models.TournamentForManipulationDto, Entities.Tournament>(); cfg.CreateMap <Models.TournamentForUpdateDto, Entities.Tournament>(); cfg.CreateMap <Entities.Tournament, Models.TournamentForUpdateDto>(); // set mapping cfg.CreateMap <Entities.Set, Models.SetDtoForDisplay>(); cfg.CreateMap <Models.SetDto, Entities.Set>(); cfg.CreateMap <Models.SetForCreationDto, Entities.Set>(); cfg.CreateMap <Models.SetForManipulationDto, Entities.Set>(); cfg.CreateMap <Models.SetForUpdateDto, Entities.Set>(); cfg.CreateMap <Entities.Set, Models.SetForUpdateDto>(); }); //comment out this line when doing db migrations //hartPRContext.EnsureSeedDataForContext(); //add first to reject requests. app.UseIpRateLimiting(); //add to authorize app.UseAuthentication(); //add for CORS app.UseCors("CorsPolicy"); //app.UseResponseCaching(); app.UseHttpCacheHeaders(); app.UseMvc(); }
public HartPRRepository(HartPRContext context, IPropertyMappingService propertyMappingService) { _context = context; _propertyMappingService = propertyMappingService; }