public ActionResult GetAddsAreaChart(int effectedDays, string type) { AreaChartViewModel payload = new AreaChartViewModel(); try { //List<HitCounterDetailViewModel> Expression <Func <HitCounterDetailViewModel, bool> > filter = null; if (effectedDays > 0) { DateTime lastDate = DateTime.Now.AddDays(-1 * effectedDays); filter = (model) => (model.HitOn >= lastDate && model.HitOn <= DateTime.Now) && model.SponsorType.Equals(type); } else { filter = (model) => model.SponsorType.Equals(type); } var totalHits = this._hitCounterDetailDataRepository.GetList(filter, x => x.HitOn, false).ToList(); if (!totalHits.IsEmptyCollection()) { payload.labels = totalHits.Select(x => x.Name).Distinct().ToList(); var dataKeys = payload.labels.Select((x, i) => new { key = x, value = type + (i + 1) }) .ToDictionary(x => x.key, x => x.value); payload.ykeys = dataKeys.Select(x => x.Value.ToString()).ToList(); payload.labels = dataKeys.Select(x => x.Key.ToString()).ToList(); var groupData = totalHits.GroupBy(x => new { x.Name, x.HitOn }) .Select(y => new { date = y.Key.HitOn.ToString("yyyy-MM-dd"), name = dataKeys[y.Key.Name], count = y.Count() }); var pivotData = groupData.Pivot(x => x.date, x => x.name, x => x.Sum(a => a.count).ToString()); foreach (var item in pivotData) { item.Value.Add("date", item.Key); } payload.xkey = "date"; payload.data = pivotData.Select(x => x.Value).ToList(); } } catch (Exception ex) { ex.ExceptionValueTracker(); } return(new JSONActionResult(payload)); }
public ActionResult GetAddsAreaChart(int effectedDays, string type) { AreaChartViewModel payload = new AreaChartViewModel(); try { //List<HitCounterDetailViewModel> Expression<Func<HitCounterDetailViewModel, bool>> filter = null; if (effectedDays > 0) { DateTime lastDate = DateTime.Now.AddDays(-1 * effectedDays); filter = (model) => (model.HitOn >= lastDate && model.HitOn <= DateTime.Now) && model.SponsorType.Equals(type); } else filter = (model) => model.SponsorType.Equals(type); var totalHits = this._hitCounterDetailDataRepository.GetList(filter, x => x.HitOn, false).ToList(); if (!totalHits.IsEmptyCollection()) { payload.labels = totalHits.Select(x => x.Name).Distinct().ToList(); var dataKeys = payload.labels.Select((x, i) => new { key = x, value = type + (i + 1) }) .ToDictionary(x => x.key, x => x.value); payload.ykeys = dataKeys.Select(x => x.Value.ToString()).ToList(); payload.labels = dataKeys.Select(x => x.Key.ToString()).ToList(); var groupData = totalHits.GroupBy(x => new { x.Name, x.HitOn }) .Select(y => new { date = y.Key.HitOn.ToString("yyyy-MM-dd"), name = dataKeys[y.Key.Name], count = y.Count() }); var pivotData = groupData.Pivot(x => x.date, x => x.name, x => x.Sum(a => a.count).ToString()); foreach (var item in pivotData) item.Value.Add("date", item.Key); payload.xkey = "date"; payload.data = pivotData.Select(x => x.Value).ToList(); } } catch (Exception ex) { ex.ExceptionValueTracker(); } return new JSONActionResult(payload); }