public IActionResult Visit() { var errorMessages = new List <string>(); //var lang = Request.Headers["language"].ToString(); try { var ip = _accessor.ActionContext.HttpContext.Connection.RemoteIpAddress.ToString(); // ip = "77.204.246.110"; var visit = _visitRepository.FindByIP(ip); if (visit != null) { var isNewDay = (DateTime.Now - visit.DateTime.Value).TotalHours > 24; if (!isNewDay) { visit.DayVisitsCount++; visit.BrowserInfo = _accessor.ActionContext.HttpContext.Request.Headers["User-Agent"][0]; var createdVisit = _visitRepository.Update(visit); return(Ok(new { visitsCount = _visitRepository.GetVisits().Count })); } else { var createdVisit = CreateVisit(ip); return(Ok(new { visitsCount = _visitRepository.GetVisits().Count })); } } else { var createdVisit = CreateVisit(ip); return(Ok(new { visitsCount = _visitRepository.GetVisits().Count })); } } catch (Exception ex) { errorMessages.Add(ex.Message); return(BadRequest(new { errors = errorMessages })); } }