public async Task InvokeAsync(HttpContext context, Adventureworks2017Context dbContext) { var path = context.Request.Path; if (!path.StartsWithSegments(ImageUrl)) { await _next(context); } else { var name = path.Value.Replace(ImageUrl + "/", ""); var isSmallImage = name.Contains("small"); var photo = isSmallImage ? dbContext.ProductPhoto.FirstOrDefault(p => p.ThumbnailPhotoFileName == name): dbContext.ProductPhoto.FirstOrDefault(p => p.LargePhotoFileName == name); if (photo == null) { photo = dbContext.ProductPhoto.FirstOrDefault(p => p.ProductPhotoId == 1); } if (photo != null) { context.Response.OnStarting(state => { var httpContext = (HttpContext) state; httpContext.Response.Headers.Add("Cache-Control", "public, max-age=31536000"); return Task.FromResult(0); }, context); await context.Response.Body.WriteAsync(isSmallImage ? photo.ThumbNailPhoto : photo.LargePhoto); } else { await _next(context); } } }
public ProductsController(Adventureworks2017Context context) { _context = context; }
public PeopleController(Adventureworks2017Context context) { _context = context; }
public EmployeesController(Adventureworks2017Context context) { _context = context; }
public EmailAddressesController(Adventureworks2017Context context) { _context = context; }