Ejemplo n.º 1
0
        public async Task Invoke(HttpContext httpContext, IUserAgentService userAgentService,
                                 WrinkMeDataContext context)
        {
            var uaHeader = StringValues.Empty;

            httpContext.Request.Headers.TryGetValue("User-Agent", out uaHeader);
            var parsedUserAgent = userAgentService.ParseUserAgent(uaHeader);

            if (httpContext.Request.Path.ToString().Length == 9)
            {
                var token    = httpContext.Request.Path.ToString().Substring(1);
                var shortUrl = context.ShortUrls
                               .Include(s => s.Requests)
                               .FirstOrDefault(su => su.Token == token);
                if (shortUrl != null)
                {
                    shortUrl.Requests.Add(parsedUserAgent);
                    await context.SaveChangesAsync();

                    httpContext.Response.Redirect(shortUrl.OriginalUrl.ToString());
                }

                else
                {
                    httpContext.Response.Redirect(httpContext.Request.Host.ToString());
                }
            }


            await _next(httpContext);
        }
Ejemplo n.º 2
0
 public DbCleaner(WrinkMeDataContext ctx)
 {
     _ctx = ctx;
 }
Ejemplo n.º 3
0
 public UserRepository(IDbContextFactory <WrinkMeDataContext> ctx)
 {
     _ctx = ctx.CreateDbContext();
 }