public string SaveUser(Contract_JMMUser user) { JMMUserRepository repUsers = new JMMUserRepository(); try { bool existingUser = false; bool updateStats = false; JMMUser jmmUser = null; if (user.JMMUserID.HasValue) { jmmUser = repUsers.GetByID(user.JMMUserID.Value); if (jmmUser == null) return "User not found"; existingUser = true; } else { jmmUser = new JMMUser(); updateStats = true; } if (existingUser && jmmUser.IsAniDBUser != user.IsAniDBUser) updateStats = true; jmmUser.HideCategories = user.HideCategories; jmmUser.IsAniDBUser = user.IsAniDBUser; jmmUser.IsTraktUser = user.IsTraktUser; jmmUser.IsAdmin = user.IsAdmin; jmmUser.Username = user.Username; jmmUser.CanEditServerSettings = user.CanEditServerSettings; jmmUser.PlexUsers = user.PlexUsers; if (string.IsNullOrEmpty(user.Password)) jmmUser.Password = ""; // make sure that at least one user is an admin if (jmmUser.IsAdmin == 0) { bool adminExists = false; List<JMMUser> users = repUsers.GetAll(); foreach (JMMUser userOld in users) { if (userOld.IsAdmin == 1) { if (existingUser) { if (userOld.JMMUserID != jmmUser.JMMUserID) adminExists = true; } else adminExists = true; } } if (!adminExists) return "At least one user must be an administrator"; } repUsers.Save(jmmUser); // update stats if (updateStats) { AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); foreach (AnimeSeries ser in repSeries.GetAll()) ser.QueueUpdateStats(); } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return ex.Message; } return ""; }
public string DeleteUser(int userID) { JMMUserRepository repUsers = new JMMUserRepository(); try { JMMUser jmmUser = repUsers.GetByID(userID); if (jmmUser == null) return "User not found"; // make sure that at least one user is an admin if (jmmUser.IsAdmin == 1) { bool adminExists = false; List<JMMUser> users = repUsers.GetAll(); foreach (JMMUser userOld in users) { if (userOld.IsAdmin == 1) { if (userOld.JMMUserID != jmmUser.JMMUserID) adminExists = true; } } if (!adminExists) return "At least one user must be an administrator"; } repUsers.Delete(userID); // delete all user records AnimeSeries_UserRepository repSeries = new AnimeSeries_UserRepository(); foreach (AnimeSeries_User ser in repSeries.GetByUserID(userID)) repSeries.Delete(ser.AnimeSeries_UserID); AnimeGroup_UserRepository repGroup = new AnimeGroup_UserRepository(); foreach (AnimeGroup_User grp in repGroup.GetByUserID(userID)) repGroup.Delete(grp.AnimeGroup_UserID); AnimeEpisode_UserRepository repEpisode = new AnimeEpisode_UserRepository(); foreach (AnimeEpisode_User ep in repEpisode.GetByUserID(userID)) repEpisode.Delete(ep.AnimeEpisode_UserID); VideoLocal_UserRepository repVids = new VideoLocal_UserRepository(); foreach (VideoLocal_User vid in repVids.GetByUserID(userID)) repVids.Delete(vid.VideoLocal_UserID); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); return ex.Message; } return ""; }
private static void CreateInitialUsers() { JMMUserRepository repUsers = new JMMUserRepository(); if (repUsers.GetAll().Count() > 0) return; JMMUser defaultUser = new JMMUser(); defaultUser.CanEditServerSettings = 1; defaultUser.HideCategories = ""; defaultUser.IsAdmin = 1; defaultUser.IsAniDBUser = 1; defaultUser.IsTraktUser = 1; defaultUser.Password = ""; defaultUser.Username = "******"; repUsers.Save(defaultUser); JMMUser familyUser = new JMMUser(); familyUser.CanEditServerSettings = 1; familyUser.HideCategories = "Ecchi,Nudity,Sex,Sexual Abuse,Horror,Erotic Game,Incest,18 Restricted"; familyUser.IsAdmin = 1; familyUser.IsAniDBUser = 1; familyUser.IsTraktUser = 1; familyUser.Password = ""; familyUser.Username = "******"; repUsers.Save(familyUser); }
/*public List<Contract_AniDBAnime> GetMiniCalendar(int numberOfDays) { AniDB_AnimeRepository repAnime = new AniDB_AnimeRepository(); JMMUserRepository repUsers = new JMMUserRepository(); // get all the series List<Contract_AniDBAnime> animeList = new List<Contract_AniDBAnime>(); try { List<AniDB_Anime> animes = repAnime.GetForDate(DateTime.Today.AddDays(0 - numberOfDays), DateTime.Today.AddDays(numberOfDays)); foreach (AniDB_Anime anime in animes) { animeList.Add(anime.ToContract()); } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return animeList; }*/ public List<Contract_JMMUser> GetAllUsers() { JMMUserRepository repUsers = new JMMUserRepository(); // get all the users List<Contract_JMMUser> userList = new List<Contract_JMMUser>(); try { List<JMMUser> users = repUsers.GetAll(); foreach (JMMUser user in users) userList.Add(user.ToContract()); } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return userList; }
public void UpdateGroupFilterUsingGroup(int groupid) { AnimeGroupRepository repGroups = new AnimeGroupRepository(); AnimeGroup_UserRepository repUserGroups = new AnimeGroup_UserRepository(); JMMUserRepository repUser = new JMMUserRepository(); GroupFilterRepository repGrpFilter = new GroupFilterRepository(); AnimeGroup grp = repGroups.GetByID(groupid); if (grp.AnimeGroupParentID.HasValue) return; foreach (JMMUser user in repUser.GetAll()) { AnimeGroup_User userRec = repUserGroups.GetByUserAndGroupID(user.JMMUserID, groupid); Dictionary<int, HashSet<int>> groupfilters; if (StatUserGroupFilter.ContainsKey(user.JMMUserID)) groupfilters = StatUserGroupFilter[user.JMMUserID]; else { groupfilters = new Dictionary<int, HashSet<int>>(); StatUserGroupFilter.Add(user.JMMUserID, groupfilters); } List<GroupFilter> gfs = repGrpFilter.GetAll(); GroupFilter gfgf = new GroupFilter(); gfgf.GroupFilterName = "All"; gfs.Add(gfgf); foreach (GroupFilter gf in gfs) { HashSet<int> groups; if (groupfilters.ContainsKey(gf.GroupFilterID)) groups = groupfilters[gf.GroupFilterID]; else { groups = new HashSet<int>(); groupfilters.Add(gf.GroupFilterID, groups); } if (groups.Contains(groupid)) groups.Remove(groupid); if (EvaluateGroupFilter(gf, grp, user, userRec)) groups.Add(grp.AnimeGroupID); } } }
/// <summary> /// Update the stats for this group based on the child series /// Assumes that all the AnimeSeries have had their stats updated already /// </summary> public void UpdateStats(bool watchedStats, bool missingEpsStats) { List<AnimeSeries> seriesList = GetAllSeries(); JMMUserRepository repUsers = new JMMUserRepository(); List<JMMUser> allUsers = repUsers.GetAll(); if (watchedStats) { foreach (JMMUser juser in allUsers) { AnimeGroup_User userRecord = GetUserRecord(juser.JMMUserID); if (userRecord == null) userRecord = new AnimeGroup_User(juser.JMMUserID, this.AnimeGroupID); // reset stats userRecord.WatchedCount = 0; userRecord.UnwatchedEpisodeCount = 0; userRecord.PlayedCount = 0; userRecord.StoppedCount = 0; userRecord.WatchedEpisodeCount = 0; userRecord.WatchedDate = null; foreach (AnimeSeries ser in seriesList) { AnimeSeries_User serUserRecord = ser.GetUserRecord(juser.JMMUserID); if (serUserRecord != null) { userRecord.WatchedCount += serUserRecord.WatchedCount; userRecord.UnwatchedEpisodeCount += serUserRecord.UnwatchedEpisodeCount; userRecord.PlayedCount += serUserRecord.PlayedCount; userRecord.StoppedCount += serUserRecord.StoppedCount; userRecord.WatchedEpisodeCount += serUserRecord.WatchedEpisodeCount; if (serUserRecord.WatchedDate.HasValue) { if (userRecord.WatchedDate.HasValue) { if (serUserRecord.WatchedDate > userRecord.WatchedDate) userRecord.WatchedDate = serUserRecord.WatchedDate; } else userRecord.WatchedDate = serUserRecord.WatchedDate; } } } // now update the stats for the groups logger.Trace("Updating stats for {0}", this.ToString()); AnimeGroup_UserRepository rep = new AnimeGroup_UserRepository(); rep.Save(userRecord); } } if (missingEpsStats) { this.MissingEpisodeCount = 0; this.MissingEpisodeCountGroups = 0; foreach (AnimeSeries ser in seriesList) { this.MissingEpisodeCount += ser.MissingEpisodeCount; this.MissingEpisodeCountGroups += ser.MissingEpisodeCountGroups; } AnimeGroupRepository repGrp = new AnimeGroupRepository(); repGrp.Save(this); } }
public void UpdateGroupFilterUsingGroupFilter(int groupfilter) { AnimeGroupRepository repGroups = new AnimeGroupRepository(); AnimeGroup_UserRepository repUserGroups = new AnimeGroup_UserRepository(); JMMUserRepository repUser =new JMMUserRepository(); GroupFilterRepository repGrpFilter=new GroupFilterRepository(); GroupFilter gf = repGrpFilter.GetByID(groupfilter); if (gf==null) return; foreach(JMMUser user in repUser.GetAll()) { Dictionary<int, HashSet<int>> groupfilters; if (StatUserGroupFilter.ContainsKey(user.JMMUserID)) groupfilters = StatUserGroupFilter[user.JMMUserID]; else { groupfilters = new Dictionary<int, HashSet<int>>(); StatUserGroupFilter.Add(user.JMMUserID, groupfilters); } HashSet<int> groups; if (groupfilters.ContainsKey(groupfilter)) groups = groupfilters[groupfilter]; else { groups = new HashSet<int>(); groupfilters.Add(groupfilter, groups); } groups.Clear(); List<AnimeGroup> allGrps = repGroups.GetAllTopLevelGroups(); // No Need of subgroups foreach (AnimeGroup grp in allGrps) { AnimeGroup_User userRec = repUserGroups.GetByUserAndGroupID(user.JMMUserID, grp.AnimeGroupID); if (EvaluateGroupFilter(gf, grp, user, userRec)) groups.Add(grp.AnimeGroupID); } } }
public void UpdatePlexAnimeGroup(ISession session, AnimeGroup grp, List<AnimeSeries> allSeries) { JMMUserRepository repUser = new JMMUserRepository(); AnimeGroup_UserRepository repUserGroups = new AnimeGroup_UserRepository(); foreach (JMMUser user in repUser.GetAll(session)) { AnimeGroup_User userRec = repUserGroups.GetByUserAndGroupID(session, user.JMMUserID, grp.AnimeGroupID); Dictionary<int, Video> cdic; if (StatPlexGroupsCache.ContainsKey(user.JMMUserID)) cdic = StatPlexGroupsCache[user.JMMUserID]; else { cdic = new Dictionary<int, Video>(); StatPlexGroupsCache[user.JMMUserID] = cdic; } cdic[grp.AnimeGroupID]=JMMServiceImplementationPlex.VideoFromAnimeGroup(session,grp,user.JMMUserID,allSeries); } }
public AnimeSeries CreateAnimeSeriesAndGroup(ISession session) { // create a new AnimeSeries record AnimeSeriesRepository repSeries = new AnimeSeriesRepository(); AnimeGroupRepository repGroups = new AnimeGroupRepository(); AnimeSeries ser = new AnimeSeries(); ser.Populate(this); JMMUserRepository repUsers = new JMMUserRepository(); List<JMMUser> allUsers = repUsers.GetAll(session); // create the AnimeGroup record // check if there are any existing groups we could add this series to bool createNewGroup = true; if (ServerSettings.AutoGroupSeries) { List<AnimeGroup> grps = AnimeGroup.GetRelatedGroupsFromAnimeID(session, ser.AniDB_ID); // only use if there is just one result if (grps != null && grps.Count > 0) { ser.AnimeGroupID = grps[0].AnimeGroupID; createNewGroup = false; } } if (createNewGroup) { AnimeGroup anGroup = new AnimeGroup(); anGroup.Populate(ser); repGroups.Save(anGroup); ser.AnimeGroupID = anGroup.AnimeGroupID; } repSeries.Save(ser); // check for TvDB associations CommandRequest_TvDBSearchAnime cmd = new CommandRequest_TvDBSearchAnime(this.AnimeID, false); cmd.Save(); // check for Trakt associations if (ServerSettings.Trakt_IsEnabled && !string.IsNullOrEmpty(ServerSettings.Trakt_AuthToken)) { CommandRequest_TraktSearchAnime cmd2 = new CommandRequest_TraktSearchAnime(this.AnimeID, false); cmd2.Save(); } return ser; }
public void UpdateKodiAnimeGroup(ISession session, AnimeGroup grp, List<AnimeSeries> allSeries) { JMMUserRepository repUser = new JMMUserRepository(); AnimeGroup_UserRepository repUserGroups = new AnimeGroup_UserRepository(); foreach (JMMUser user in repUser.GetAll(session)) { AnimeGroup_User userRec = repUserGroups.GetByUserAndGroupID(session, user.JMMUserID, grp.AnimeGroupID); Dictionary<int, JMMContracts.KodiContracts.Video> cdic; if (StatKodiGroupsCache.ContainsKey(user.JMMUserID)) cdic = StatKodiGroupsCache[user.JMMUserID]; else { cdic = new Dictionary<int, JMMContracts.KodiContracts.Video>(); StatKodiGroupsCache[user.JMMUserID] = cdic; } cdic[grp.AnimeGroupID] = KodiHelper.VideoFromAnimeGroup(session, grp, user.JMMUserID, allSeries); } }
public System.IO.Stream GetUsers() { KodiContract_Users gfs = new KodiContract_Users(); try { gfs.Users=new List<KodiContract_User>(); JMMUserRepository repUsers = new JMMUserRepository(); foreach (JMMUser us in repUsers.GetAll()) { KodiContract_User p = new KodiContract_User(); p.id = us.JMMUserID.ToString(); p.name = us.Username; gfs.Users.Add(p); } } catch (Exception ex) { logger.ErrorException(ex.ToString(), ex); } return KodiHelper.GetStreamFromXmlObject(gfs); }