public List <ChartPointWrapper> GetVisitStatistics(ApiDateTime fromDate, ApiDateTime toDate) { SecurityContext.DemandPermissions(Tenant, SecutiryConstants.EditPortalSettings); var from = TenantUtil.DateTimeFromUtc(fromDate); var to = TenantUtil.DateTimeFromUtc(toDate); var points = new List <ChartPointWrapper>(); if (from.CompareTo(to) >= 0) { return(points); } for (var d = new DateTime(from.Ticks); d.Date.CompareTo(to.Date) <= 0; d = d.AddDays(1)) { points.Add(new ChartPointWrapper { DisplayDate = d.Date.ToShortDateString(), Date = d.Date, Hosts = 0, Hits = 0 }); } var hits = StatisticManager.GetHitsByPeriod(Tenant.TenantId, from, to); var hosts = StatisticManager.GetHostsByPeriod(Tenant.TenantId, from, to); if (hits.Count == 0 || hosts.Count == 0) { return(points); } hits.Sort((x, y) => x.VisitDate.CompareTo(y.VisitDate)); hosts.Sort((x, y) => x.VisitDate.CompareTo(y.VisitDate)); for (int i = 0, n = points.Count, hitsNum = 0, hostsNum = 0; i < n; i++) { while (hitsNum < hits.Count && points[i].Date.CompareTo(hits[hitsNum].VisitDate.Date) == 0) { points[i].Hits += hits[hitsNum].VisitCount; hitsNum++; } while (hostsNum < hosts.Count && points[i].Date.CompareTo(hosts[hostsNum].VisitDate.Date) == 0) { points[i].Hosts++; hostsNum++; } } return(points); }