public async Task <List <Channel> > SearchChannels(string subject, string searchQuery) { if (string.IsNullOrEmpty(subject)) { if (string.IsNullOrWhiteSpace(searchQuery)) { return(await storage.GetList <Channel>(SQLQueries.GetAllUserChannelsThatAreStreaming)); } else { return(await storage.GetList <Channel>(SQLQueries.GetUserChannelsBySearchTerm, searchQuery.ToLower())); } } else { if (string.IsNullOrWhiteSpace(searchQuery)) { return(await storage.GetList <Channel>(SQLQueries.GetUserChannelWithSubject, subject)); } else { return(await storage.GetList <Channel>(SQLQueries.GetUserChannelsBySubjectAndSearchTerm, subject, searchQuery.ToLower())); } } }
public async Task NotifyAllFollowers(Profile user) { await Task.Factory.StartNew(async() => { // Can't get channel externally, since it's out of date once the stream has started and info is updated. Channel channel = await storage.Get <Channel>(SQLQueries.GetUserChannelWithUsername, user.Username); // Start both tasks var userFollowsTask = await storage.GetList <Follow>(SQLQueries.GetAllFollowersWithId, user.Id); var topicFollowsTask = await storage.GetList <TopicFollow>(SQLQueries.GetTopicFollowsBySubject, channel.StreamSubject); // Remove overlapping followers IEnumerable <TopicFollow> topicFollows = from TopicFollow topicFollow in topicFollowsTask where userFollowsTask.FirstOrDefault(userFollow => topicFollow.Follower == userFollow.FollowerUsername) == null select topicFollow; await Task.Factory.StartNew(async() => { foreach (var userFollow in userFollowsTask) { Profile userFollower = await storage.Get <Profile>(SQLQueries.GetUserWithUsername, userFollow.FollowerUsername); if (userFollower != null && userFollower.NotificationSubscribe == "True") { MimeMessage message = new MimeMessage(); string url = cookies.host + "/Stream/Live/" + user.Username; message.From.Add(new MailboxAddress(name, streamworkEmailAddress)); message.To.Add(MailboxAddress.Parse(userFollower.EmailAddress)); message.Subject = $"{user.Username} is now streaming \"{channel.StreamTitle}\" in {channel.StreamSubject}!"; message.Body = new TextPart("html") { Text = ConvertToTemplateString($"Hey there {userFollower.Name.Split('|')[0]},", $"A StreamTutor you follow, {user.Username}, is now live-streaming \"{channel.StreamTitle}\" in {channel.StreamSubject}.\n\n Tune in <a href={url}>here!</a>") }; await SendEmail(message); } } }); await Task.Factory.StartNew(async() => { foreach (var topicFollow in topicFollows) { Profile userFollower = await storage.Get <Profile>(SQLQueries.GetUserWithUsername, topicFollow.Follower); if (userFollower != null && userFollower.NotificationSubscribe == "True") { MimeMessage message = new MimeMessage(); string url = cookies.host + "/Stream/Live/" + user.Username; message.From.Add(new MailboxAddress(name, streamworkEmailAddress)); message.To.Add(MailboxAddress.Parse(userFollower.EmailAddress)); message.Subject = $"{user.Username} is now streaming \"{channel.StreamTitle}\" in {channel.StreamSubject}!"; message.Body = new TextPart("html") { Text = ConvertToTemplateString($"Hey there {userFollower.Name.Split('|')[0]},", $"{user.Username} is now live-streaming \"{channel.StreamTitle}\" in a topic you follow, {channel.StreamSubject}.\n\n Tune in <a href={url}>here!</a>") }; await SendEmail(message); } } }); }); }