public List<Contract_GroupFilterExtended> GetAllGroupFiltersExtended(int userID) { List<Contract_GroupFilterExtended> gfs = new List<Contract_GroupFilterExtended>(); try { DateTime start = DateTime.Now; GroupFilterRepository repGF = new GroupFilterRepository(); JMMUserRepository repUsers = new JMMUserRepository(); JMMUser user = repUsers.GetByID(userID); if (user == null) return gfs; List<GroupFilter> allGfs = repGF.GetAll(); TimeSpan ts = DateTime.Now - start; logger.Info("GetAllGroupFilters (Database) in {0} ms", ts.TotalMilliseconds); start = DateTime.Now; AnimeGroupRepository repGroups = new AnimeGroupRepository(); List<AnimeGroup> allGrps = repGroups.GetAllTopLevelGroups(); ts = DateTime.Now - start; logger.Info("GetAllGroups (Database) in {0} ms", ts.TotalMilliseconds); start = DateTime.Now; foreach (GroupFilter gf in allGfs) { Contract_GroupFilter gfContract = gf.ToContract(); Contract_GroupFilterExtended gfeContract = new Contract_GroupFilterExtended(); gfeContract.GroupFilter = gfContract; gfeContract.GroupCount = 0; gfeContract.SeriesCount = 0; if ((StatsCache.Instance.StatUserGroupFilter.ContainsKey(user.JMMUserID)) && (StatsCache.Instance.StatUserGroupFilter[userID].ContainsKey(gf.GroupFilterID))) { HashSet<int> groups = StatsCache.Instance.StatUserGroupFilter[user.JMMUserID][gf.GroupFilterID]; foreach (AnimeGroup grp in allGrps) { if (groups.Contains(grp.AnimeGroupID)) { // calculate stats gfeContract.GroupCount++; } } } gfs.Add(gfeContract); } ts = DateTime.Now - start; logger.Info("GetAllGroupFiltersExtended (FILTER) in {0} ms", ts.TotalMilliseconds); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return gfs; }
public Contract_GroupFilterExtended ToContractExtended(ISession session, JMMUser user) { Contract_GroupFilterExtended contract = new Contract_GroupFilterExtended(); contract.GroupFilter = this.ToContract(); contract.GroupCount = 0; contract.SeriesCount = 0; if (GroupsIds.ContainsKey(user.JMMUserID)) { contract.GroupCount = GroupsIds[user.JMMUserID].Count; } /* // find all the groups for thise group filter AnimeGroupRepository repGroups = new AnimeGroupRepository(); List<AnimeGroup> allGrps = repGroups.GetAll(session); if ((StatsCache.Instance.StatUserGroupFilter.ContainsKey(user.JMMUserID)) && (StatsCache.Instance.StatUserGroupFilter[user.JMMUserID].ContainsKey(this.GroupFilterID))) { HashSet<int> groups = StatsCache.Instance.StatUserGroupFilter[user.JMMUserID][GroupFilterID]; foreach (AnimeGroup grp in allGrps) { if (groups.Contains(grp.AnimeGroupID)) contract.GroupCount++; } }*/ return contract; }
public List<Contract_GroupFilterExtended> GetGroupFiltersExtended(int userID, int gfparentid = 0) { List<Contract_GroupFilterExtended> gfs = new List<Contract_GroupFilterExtended>(); try { JMMUser user = RepoFactory.JMMUser.GetByID(userID); if (user == null) return gfs; List<GroupFilter> allGfs = gfparentid == 0 ? RepoFactory.GroupFilter.GetTopLevel() : RepoFactory.GroupFilter.GetByParentID(gfparentid); foreach (GroupFilter gf in allGfs) { Contract_GroupFilter gfContract = gf.ToContract(); Contract_GroupFilterExtended gfeContract = new Contract_GroupFilterExtended(); gfeContract.GroupFilter = gfContract; gfeContract.GroupCount = 0; gfeContract.SeriesCount = 0; if (gf.GroupsIds.ContainsKey(user.JMMUserID)) gfeContract.GroupCount = gf.GroupsIds.Count; gfs.Add(gfeContract); } } catch (Exception ex) { logger.Error( ex,ex.ToString()); } return gfs; }