public static ShowcaseItemMetric GetByID(int ShowcaseItemMetricID, IEnumerable <string> includeList = null) { ShowcaseItemMetric obj = null; string key = cacheKeyPrefix + ShowcaseItemMetricID + GetCacheIncludeText(includeList); ShowcaseItemMetric tmpClass = null; if (Cache.IsEnabled) { if (Cache.IsEmptyCacheItem(key)) { return(null); } tmpClass = Cache[key] as ShowcaseItemMetric; } if (tmpClass != null) { obj = tmpClass; } else { using (Entities entity = new Entities()) { IQueryable <ShowcaseItemMetric> itemQuery = AddIncludes(entity.ShowcaseItemMetric, includeList); obj = itemQuery.FirstOrDefault(n => n.ShowcaseItemMetricID == ShowcaseItemMetricID); } Cache.Store(key, obj); } return(obj); }
public ShowcaseItemMetric(ShowcaseItemMetric objectToCopy) { ClickTypeID = objectToCopy.ClickTypeID; Date = objectToCopy.Date; SessionID = objectToCopy.SessionID; ShowcaseItemID = objectToCopy.ShowcaseItemID; ShowcaseItemMetricID = objectToCopy.ShowcaseItemMetricID; UserID = objectToCopy.UserID; }
public static List <ShowcaseItemMetric> GetMostPopularItems(int numberOfShowcaseItems, int?showcaseID, DateTime beginDate, DateTime endDate) { List <ShowcaseItemMetric> objects; string key = cacheKeyPrefix + "GetMostPopularItems_" + numberOfShowcaseItems + "_" + showcaseID + "_" + beginDate + "_" + endDate; List <ShowcaseItemMetric> tmpList = null; if (Cache.IsEnabled) { tmpList = Cache[key] as List <ShowcaseItemMetric>; } if (tmpList != null) { objects = tmpList; } else { int totalCount = 0; objects = new List <ShowcaseItemMetric>(); using (Entities entity = new Entities()) { var itemQuery = entity.ShowcaseItemMetric.Where(s => s.Date >= beginDate && s.Date <= endDate); if (showcaseID.HasValue) { itemQuery = itemQuery.Where(s => s.ShowcaseItem.ShowcaseID == showcaseID.Value); } var queriedList = itemQuery.GroupBy(s => new { s.ShowcaseItemID, s.ShowcaseItem.Title }).Select(s => new { s.Key.ShowcaseItemID, s.Key.Title, Count = s.Select(m => m.SessionID).Distinct().Count() }).OrderByDescending(s => s.Count).ThenBy(s => s.Title).Take(numberOfShowcaseItems).ToList(); foreach (var item in queriedList) { ShowcaseItemMetric obj = new ShowcaseItemMetric(); obj.ShowcaseItemID = item.ShowcaseItemID; obj.ShowcaseItemTitle = item.Title; obj.Count = item.Count; totalCount += item.Count; objects.Add(obj); } } foreach (ShowcaseItemMetric obj in objects) { obj.Percentage = obj.Count / (decimal)totalCount; } Cache.Store(key, objects); } return(objects); }