public async Task NotifyUsers(IEnumerable <RequestedModel> modelChanged, string apiKey) { try { var plexUser = PlexApi.GetUsers(apiKey); var userAccount = PlexApi.GetAccount(apiKey); var adminUsername = userAccount.Username ?? string.Empty; var users = UserNotifyRepo.GetAll().ToList(); Log.Debug("Notifying Users Count {0}", users.Count); foreach (var model in modelChanged) { var selectedUsers = users.Select(x => x.Username).Intersect(model.RequestedUsers, StringComparer.CurrentCultureIgnoreCase); foreach (var user in selectedUsers) { Log.Info("Notifying user {0}", user); if (user.Equals(adminUsername, StringComparison.CurrentCultureIgnoreCase)) { Log.Info("This user is the Plex server owner"); await PublishUserNotification(userAccount.Username, userAccount.Email, model.Title, model.PosterPath); return; } var email = plexUser.User.FirstOrDefault(x => x.Username.Equals(user, StringComparison.CurrentCultureIgnoreCase)); if (email == null) { Log.Info("There is no email address for this Plex user, cannot send notification"); // We do not have a plex user that requested this! continue; } Log.Info("Sending notification to: {0} at: {1}, for title: {2}", email.Username, email.Email, model.Title); await PublishUserNotification(email.Username, email.Email, model.Title, model.PosterPath); } } } catch (Exception e) { Log.Error(e); } }