public Task LogAuthRecord(string userId, HttpContext httpContext, bool success, string appId) { if (httpContext.AllowTrack() || success == false) { var log = new AuditLogLocal { UserId = userId, IPAddress = httpContext.Connection.RemoteIpAddress.ToString(), Success = success, AppId = appId }; _dbContext.AuditLogs.Add(log); return(_dbContext.SaveChangesAsync()); } else { var log = new AuditLogLocal { UserId = userId, IPAddress = "Unknown(because of `dnt` policy)", Success = success, AppId = appId }; _dbContext.AuditLogs.Add(log); return(_dbContext.SaveChangesAsync()); } }
public async Task <IActionResult> DoSearch([FromQuery(Name = "q")] string question, int page = 1) { if (string.IsNullOrWhiteSpace(question)) { return(Redirect("/")); } ViewBag.CurrentPage = page; var market = CultureInfo.CurrentCulture.Name; var result = await _cache.GetAndCache($"search-content-{market}-{page}-" + question, () => _searchService.DoSearch(question, market, page)); ViewBag.Entities = await _cache.GetAndCache($"search-entity-{market}-" + question, () => _searchService.EntitySearch(question, market)); if (HttpContext.AllowTrack()) { await _dbContext.SearchHistories.AddAsync(new SearchHistory { Question = question, TriggerUserId = User.GetUserId(), Page = page }); await _dbContext.SaveChangesAsync(); } return(View(result)); }