public static bool CheckIfGameIsCurrent(Game game, Channel channel) { bool gameIsCurrent = channel.DailyActivities .FirstOrDefault(d => d.ActivityDate == DateTime.Now) .GameInstances.Any(gi => gi.Game == game); return gameIsCurrent; }
public static Channel CreateChannel() { var moonDb = new MoonAidAzureContext(); var channel = new Channel(); moonDb.Entry<Channel>(channel).State = EntityState.Added; moonDb.SaveChanges(); return channel; }
public static Channel SyncChannels(TwitchChannel twitchChannel, Channel channel) { channel.CreatedAt = twitchChannel.CreatedAt; channel.UpdatedAt = twitchChannel.UpdatedAt; channel.TwitchChannelName = twitchChannel.Name; channel.TwitchChannelId = twitchChannel.Id; if (channel.Urls.Any(u => u.TheUrl != twitchChannel.Url)) { channel.Urls.Add(new Url { TheUrl = twitchChannel.Url, CreatedAt = DateTime.Now }); } return channel; }
public static bool DeleteChannel(Channel channel) { var moonDb = new MoonAidAzureContext(); try { moonDb.Entry(channel).State = EntityState.Deleted; moonDb.SaveChanges(); return true; } catch (Exception ex) { throw; } }
public static void CheckGameStatus(string twitchGameName, Channel channel) { var game = GameInstanceMethods.GetGameByTwitchName(twitchGameName); game = game == null ? GameInstanceMethods.CreateNewGame(twitchGameName) : game; bool gameIsCurrent = GameInstanceMethods.CheckIfGameIsCurrent(game, channel); if (gameIsCurrent) { var gameInstance = GameInstanceMethods.GetGameInstance(channel.ChannelId, twitchGameName); if (gameInstance.TimeSpanAdded == null) { TimeSpan spanBetweenFromAndNow = gameInstance.PlayedFrom - DateTime.Now; gameInstance.TotalTimePlayed = spanBetweenFromAndNow; gameInstance.TimeSpanAdded = DateTime.Now; } else { TimeSpan spanSinceLastCheck = gameInstance.TimeSpanAdded - DateTime.Now; gameInstance.TotalTimePlayed += spanSinceLastCheck; } StatisticService.CheckStatisticsForGame(channel.Statistic, game); GameInstanceMethods.SaveInstance(gameInstance); } else { var gameInstance = new GameInstance(game) { TotalViewersCount = 0, ChannelId = channel.ChannelId }; GameInstanceMethods.AddGameInstance(gameInstance); channel.DailyActivities .FirstOrDefault(d => d.ActivityDate == DateTime.Now) .GameInstances.Add(gameInstance); } }
public static void AddFollowers(Channel channel, IQueryable<Follow> twitchList) { var moonDb = new MoonAidAzureContext(); var connections = FollowToConnectionConverter(twitchList, channel); var activity = channel.DailyActivities .FirstOrDefault(d => d.ActivityDate == DateTime.Now); foreach (var item in connections) { activity.Connections.Add(item); } moonDb.Entry(connections).State = EntityState.Added; moonDb.Entry(activity).State = EntityState.Modified; moonDb.SaveChanges(); }
public static void CheckForFollowers(TwitchList<Follow> followers, Channel channel) { var followingChannel = ChannelMethods.GetFollowers(channel); var newFollowers = followingChannel .SelectMany(fc => followers.List .Where(f => f.Channel.Id != fc.TwitchChannelId)) .AsQueryable(); // användare som finns i databasen men inte finns i followers var followersToDelete = followers.List .SelectMany(f => followingChannel .Where(fc => fc.TwitchChannelId != f.Channel.Id)) .AsQueryable(); ChannelMethods.AddFollowers(channel, newFollowers); ChannelMethods.RemoveFollowers(channel, followersToDelete); }
public static Channel SwitchPublicState(Channel channel, bool publicState) { var moonDb = new MoonAidAzureContext(); channel.IsPublic = publicState; moonDb.Entry(channel).State = EntityState.Modified; moonDb.SaveChanges(); return channel; }
public static Channel SwitchMailState(Channel channel, bool mailState) { var moonDb = new MoonAidAzureContext(); channel.ReceieveMailSwitch = mailState; moonDb.Entry(channel).State = EntityState.Modified; moonDb.SaveChanges(); return channel; }
public static void SaveChannel(Channel channel) { var moonDb = new MoonAidAzureContext(); moonDb.Entry(channel).State = EntityState.Modified; moonDb.SaveChanges(); }
public static void RemoveFollowers(Channel channel, IQueryable<Connection> followersToDelete) { var moonDb = new MoonAidAzureContext(); moonDb.Entry(followersToDelete).State = EntityState.Deleted; moonDb.SaveChanges(); }
public static void DeleteChannel(Channel channel) { // TODO: Cascading delete? ChannelMethods.DeleteChannel(channel); }
public static Channel SwitchReceieveMail(Channel channel, bool mailState) { return ChannelMethods.SwitchMailState(channel, mailState); }
public static Channel SwitchPublic(Channel channel, bool publicState) { return ChannelMethods.SwitchPublicState(channel, publicState); }
public static void SaveChannel(Channel channel) { StatisticService.StopStreamTimer(channel.Statistic); ChannelLoggerService.SaveChannelLogger(channel.ChannelLogger); ChannelMethods.SaveChannel(channel); }
public static List<UserProfileViewModel> GetUsersForViewModel(Channel channel) { var list = new List<UserProfileViewModel>(); var users = ChannelMethods.GetFollowers(channel); list = ModelConverters.ConnectionToUserProfile(users); return list; }
public static IEnumerable<Connection> FollowToConnectionConverter(IEnumerable<Follow> twitchList, Channel channel) { var connections = new List<Connection>(); IQueryable<UserProfile> newUsers; foreach (var item in twitchList) { // TODO: READUP HERE PLZ // kolla om det är en ny användare eller inte // annars gör den // här kolla om den connection finns med hjälp av follow objektet // och titta efter users i ett annat skede bool userExist = UserService.CheckUserExists(item) var userProfile = new UserProfile() { item.Channel.Id }; connections.Add(new Connection { IsFollower = true, UserProfile = userProfile, UserProfileId = userProfile.UserProfileId, TimesConnectedCount = 1, // gör en metod som kollar hur många gånger användaren connectat ChannelId = channel.ChannelId, Channel = channel, FollowerConnectionCreatedAt = item.CreatedAt, IsSubscriber = true, // gör en etod som kollar om den är subscirber eller inte, tänk på om den används på flera ställen LastSeenAt = DateTime.Now, // gör en metod som kollar om dne är ny eller inte och sätter datumet på lastseen därefter TwitchChannelId = channel.PublicChannelId, }); return connections; } return connections; }
public static IEnumerable<Connection> GetFollowers(Channel channel) { var followers = channel.DailyActivities .SelectMany(x => x.Connections .Where(y => y.ChannelId == channel.ChannelId && y.IsFollower)); return followers; }