public void SendEmailsForPost(Post post, Channel sourceChannel) { var message = new MailMessage(); message.From = new MailAddress(_fromEmail, "Info Hub"); message.Subject = string.Format("New Infohub message for '{0}'", sourceChannel.Name); message.Body = _GetEmailText(post); message.BodyEncoding = Encoding.UTF8; foreach (var user in sourceChannel.Users) { if (user.User.EmailNotificationEnabled) message.Bcc.Add(user.User.Email); } _client.SendAsync(message, null); }
private void _UnregisterFromChannel(Channel channel) { var channelForUser = _GetChannelForCurrentUserById(channel); if (channelForUser != null) { _dbContext.SubscribedChannelsByUser.Remove(channelForUser); foreach (var postForUser in _dbContext.PostsForUser.Where(x => x.SourceChannel.Id == channel.Id && x.User.Id == CurrentUser.Id)) _dbContext.PostsForUser.Remove(postForUser); } }
private void _RegisterForChannel(Channel channel) { channel.Users.Add(new SubscribedChannelByUser() {User = CurrentUser}); var recentPostsForChannel = _dbContext.Posts.Where(x => x.Channel.Id == channel.Id) .OrderByDescending(x => x.Date).Take(RECENT_CHANNEL_COUNT).ToArray(); foreach (var recentPost in recentPostsForChannel) _GetPostForUser(recentPost, CurrentUser, channel); }
private PostForUser _GetPostForUser(Post post, User user, Channel sourceChannel) { var postForUser = _dbContext.PostsForUser.SingleOrDefault(x => x.Post.Id == post.Id && x.User.Id == user.Id && x.SourceChannel.Id == sourceChannel.Id); if (postForUser == null) { postForUser = new PostForUser { Post = post, User = user, WasRead = false, SourceChannel = sourceChannel }; _dbContext.PostsForUser.Add(postForUser); } return postForUser; }
private ChannelViewModel[] _GetChannelsForParent(Channel parent, IEnumerable<Channel> allChannels, Func<Channel, bool> getIsUserSubscribed) { var channels = allChannels.Where(x => x.ParentChannel == parent).ToArray(); var results = Mapper.Map<ChannelViewModel[]>(channels); for (int i = 0; i < channels.Length; i++) { results[i].IsUserSubscribed = getIsUserSubscribed(channels[i]); results[i].Children = _GetChannelsForParent(channels[i], allChannels, getIsUserSubscribed); } return results; }
private SubscribedChannelByUser _GetChannelForCurrentUserById(Channel channel) { return _dbContext.SubscribedChannelsByUser.SingleOrDefault(x => x.User.Id == CurrentUser.Id && x.Channel.Id == channel.Id); }