public MagnumPhotosRepository(MagnumPhotosContext context, ILogger <MagnumPhotosRepository> logger, IPropertyMappingService propertyMappingService) { _logger = logger; _context = context; _propertyMappingService = propertyMappingService; }
public static async Task Initialize( MagnumPhotosContext context, ILogger <MagnumPhotosContextInitializer> logger) { context.Database.EnsureCreated(); if (!context.Photographers.Any()) { context.Photographers.AddRange( GetPreconfiguredPhotographers()); await context.SaveChangesAsync(); } if (!context.Books.Any()) { context.Books.AddRange( GetPreconfiguredBooks()); await context.SaveChangesAsync(); } }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, MagnumPhotosContext magnumPhotosContext) { 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(options => { options.CreateMap <Entities.Photographer, Models.PhotographerDto> () .ForMember(dest => dest.Name, opt => opt.MapFrom(src => $"{src.FirstName} {src.LastName}")) .ForMember(dest => dest.Age, opt => opt.MapFrom(src => src.DateOfBirth.GetCurrentAge())); options.CreateMap <Entities.Book, Models.BookDto> (); options.CreateMap <Entities.Book, Models.BookForUpdateDto> (); options.CreateMap <Entities.Photographer, Models.PhotographerForUpdateDto> (); options.CreateMap <Models.PhotographerForCreationDto, Entities.Photographer> (); options.CreateMap <Models.PhotographerForUpdateDto, Entities.Photographer> (); options.CreateMap <Models.BookForCreationDto, Entities.Book> (); options.CreateMap <Models.BookForUpdateDto, Entities.Book> (); }); app.UseIpRateLimiting(); app.UseResponseCaching(); app.UseHttpCacheHeaders(); app.UseMvc(); app.UseSwagger(c => { c.RouteTemplate = "swagger/{documentName}/swagger.json"; }); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "Magnum Photos API V1"); }); }