public List <TopContents> GetActivityContents(UserActivities ltUserActivities, int pastDays = 7) { List <TopContents> lstTopContents = new List <TopContents>(); UserActivities lstUserActivities = ltUserActivities; var checkDate = DateTime.Now.AddDays(-pastDays); //var arrDistinctDate = lstUserActivities.UserActivity.Where(x => Convert.ToDateTime(x.Date) >= checkDate).GroupBy(i => i.Date, (key, group) => group.First()).ToArray(); var arrActivities = lstUserActivities.UserActivity.Where(x => !string.IsNullOrWhiteSpace(x.Date) && Convert.ToDateTime(x.Date).Date >= checkDate.Date).GroupBy(x => new { Convert.ToDateTime(x.Date).Date, x.PagePath, x.PageTitle }).ToList(); foreach (var activity in arrActivities) { // foreach(var values in activity) // { // values. // } TopContents content = new TopContents(); content.Date = Convert.ToDateTime(activity.Key.Date).Date.ToShortDateString(); //Convert.ToDateTime(activity.Date).Date.ToShortDateString(); content.PagePath = activity.Key.PagePath; content.PageTitle = activity.Key.PageTitle; content.PageViwes = lstUserActivities.UserActivity.Where(x => !string.IsNullOrWhiteSpace(x.Date) && Convert.ToDateTime(x.Date).Date == Convert.ToDateTime(activity.Key.Date).Date).GroupBy(k => new { k.TrackerId, k.PagePath, k.PageTitle }).Count(); content.UniquePageViwes = lstUserActivities.UserActivity.Where(x => !string.IsNullOrWhiteSpace(x.Date) && Convert.ToDateTime(x.Date).Date == Convert.ToDateTime(activity.Key.Date).Date).GroupBy(k => new { k.PagePath, k.PageTitle }).Count(); content.Visits = lstUserActivities.UserActivity.Where(k => !string.IsNullOrWhiteSpace(k.Date) && Convert.ToDateTime(k.Date).Date == Convert.ToDateTime(activity.Key.Date).Date).GroupBy(l => l.TrackerId).Count(); lstTopContents.Add(content); } return(lstTopContents); }
public List <TopContents> GetActionContents(UserActivities ltUserActivities, int pastDays = 7) { List <TopContents> lstTopContents = new List <TopContents>(); UserActivities lstUserActivities = ltUserActivities; var checkDate = DateTime.Now.AddDays(-pastDays); //var arrDistinctDate = lstUserActivities.UserActivity.Where(x => Convert.ToDateTime(x.Date) >= checkDate).GroupBy(i => i.Date, (key, group) => group.First()).ToArray(); var arrActivities = lstUserActivities.UserActivity.Where(x => !string.IsNullOrWhiteSpace(x.Date) && x.ActivityType == "Action").ToList(); foreach (var activity in arrActivities) { TopContents content = new TopContents(); content.Date = Convert.ToDateTime(activity.Date).Date.ToShortDateString(); //Convert.ToDateTime(activity.Date).Date.ToShortDateString(); content.PagePath = activity.PagePath; content.PageTitle = activity.PageTitle; content.ElementName = activity.ElementName; content.ElementType = activity.ElementType; lstTopContents.Add(content); } return(lstTopContents); }