public void MovieIssueNotificationTests()
        {
            var notificationOptions = new NotificationOptions
            {
                Substitutes = new Dictionary <string, string>
                {
                    { "IssueDescription", "Desc" },
                    { "IssueCategory", "Cat" },
                    { "IssueStatus", "state" },
                    { "IssueSubject", "sub" },
                    { "NewIssueComment", "a" },
                    { "IssueUser", "User" },
                    { "IssueUserAlias", "alias" },
                    { "RequestType", "Movie" },
                }
            };
            var req = F.Build <MovieRequests>()
                      .With(x => x.RequestType, RequestType.Movie)
                      .Create();
            var customization = new CustomizationSettings();
            var userPrefs     = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);

            Assert.That("Desc", Is.EqualTo(sut.IssueDescription));
            Assert.That("Cat", Is.EqualTo(sut.IssueCategory));
            Assert.That("state", Is.EqualTo(sut.IssueStatus));
            Assert.That("a", Is.EqualTo(sut.NewIssueComment));
            Assert.That("User", Is.EqualTo(sut.UserName));
            Assert.That("alias", Is.EqualTo(sut.Alias));
            Assert.That("Movie", Is.EqualTo(sut.Type));
        }
        public void MusicNotificationTests()
        {
            var notificationOptions = new NotificationOptions();
            var req = F.Build <AlbumRequest>()
                      .With(x => x.RequestType, RequestType.Album)
                      .With(x => x.Available, true)
                      .Create();
            var customization = new CustomizationSettings
            {
                ApplicationUrl  = "url",
                ApplicationName = "name"
            };
            var userPrefs = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);

            Assert.That(req.Id.ToString(), Is.EqualTo(sut.RequestId));
            Assert.That(req.ForeignArtistId.ToString(), Is.EqualTo(sut.ProviderId));
            Assert.That(req.Title.ToString(), Is.EqualTo(sut.Title));
            Assert.That(req.RequestedUser.UserName, Is.EqualTo(sut.RequestedUser));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.Alias));
            Assert.That(req.RequestedDate.ToString("D"), Is.EqualTo(sut.RequestedDate));
            Assert.That("Album", Is.EqualTo(sut.Type));
            Assert.That(req.ReleaseDate.Year.ToString(), Is.EqualTo(sut.Year));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.MarkedAsAvailable?.ToString("D"), Is.EqualTo(sut.AvailableDate));
            Assert.That(req.Cover, Is.EqualTo(sut.PosterImage));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.UserPreference));
            Assert.That(string.Empty, Is.EqualTo(sut.AdditionalInformation));
            Assert.That("Available", Is.EqualTo(sut.RequestStatus));
            Assert.That("url", Is.EqualTo(sut.ApplicationUrl));
            Assert.That("name", Is.EqualTo(sut.ApplicationName));
        }
        public void MovieNotificationTests()
        {
            var notificationOptions = new NotificationOptions();
            var req = F.Build <MovieRequests>()
                      .With(x => x.RequestType, RequestType.Movie)
                      .With(x => x.Available, true)
                      .Create();
            var customization = new CustomizationSettings
            {
                ApplicationUrl  = "url",
                ApplicationName = "name"
            };
            var userPrefs = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);

            Assert.That(req.Id.ToString(), Is.EqualTo(sut.RequestId));
            Assert.That(req.TheMovieDbId.ToString(), Is.EqualTo(sut.ProviderId));
            Assert.That(req.Title.ToString(), Is.EqualTo(sut.Title));
            Assert.That(req.RequestedUser.UserName, Is.EqualTo(sut.RequestedUser));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.Alias));
            Assert.That(req.RequestedDate.ToString("D"), Is.EqualTo(sut.RequestedDate));
            Assert.That("Movie", Is.EqualTo(sut.Type));
            Assert.That(req.Overview, Is.EqualTo(sut.Overview));
            Assert.That(req.ReleaseDate.Year.ToString(), Is.EqualTo(sut.Year));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.MarkedAsAvailable?.ToString("D"), Is.EqualTo(sut.AvailableDate));
            Assert.That("https://image.tmdb.org/t/p/w300/" + req.PosterPath, Is.EqualTo(sut.PosterImage));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.UserPreference));
            Assert.That(string.Empty, Is.EqualTo(sut.AdditionalInformation));
            Assert.That("Available", Is.EqualTo(sut.RequestStatus));
            Assert.That("url", Is.EqualTo(sut.ApplicationUrl));
            Assert.That("name", Is.EqualTo(sut.ApplicationName));
        }
Example #4
0
        private void LoadCommon(BaseRequest req, CustomizationSettings s, UserNotificationPreferences pref)
        {
            ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s.ApplicationName;
            ApplicationUrl  = s?.ApplicationUrl.HasValue() ?? false ? s.ApplicationUrl : string.Empty;
            AvailableDate   = req?.MarkedAsAvailable?.ToString("D") ?? string.Empty;
            DenyReason      = req?.DeniedReason;
            RequestId       = req?.Id.ToString();
            RequestedUser   = req?.RequestedUser?.UserName;
            RequestedDate   = req?.RequestedDate.ToString("D");

            if (Type.IsNullOrEmpty())
            {
                Type = HumanizeReturnType(req?.RequestType);
            }

            if (UserName.IsNullOrEmpty())
            {
                UserName = req?.RequestedUser?.UserName;
            }

            if (Alias.IsNullOrEmpty())
            {
                Alias = req?.RequestedUser?.Alias.HasValue() ?? false
                    ? req.RequestedUser?.Alias
                    : req?.RequestedUser?.UserName;
            }

            if (pref != null)
            {
                UserPreference = pref.Value.HasValue() ? pref.Value : Alias;
            }
        }
 public Task UpdateUserNotificationPreferencesAsync(UserNotificationPreferences preferences)
 {
     return(_messaging.SendCommandAsync(new UpdateUserNotificationPreferencesCommand
     {
         UserNotificationPreferences = preferences
     }));
 }
        public void Setup(NotificationOptions opts, MovieRequests req, CustomizationSettings s,
                          UserNotificationPreferences pref)
        {
            LoadIssues(opts);
            LoadCommon(req, s, pref, opts);
            LoadTitle(opts, req);
            ProviderId            = req?.TheMovieDbId.ToString() ?? string.Empty;
            Year                  = req?.ReleaseDate.Year.ToString();
            Overview              = req?.Overview;
            AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;

            var img = req?.PosterPath ?? string.Empty;

            if (img.HasValue())
            {
                if (img.StartsWith("http"))
                {
                    // This means it's a legacy request from when we used TvMaze as a provider.
                    // The poster url is the fully qualified address, so just use it
                    PosterImage = img;
                }
                else
                {
                    PosterImage =
                        $"https://image.tmdb.org/t/p/w300/{img?.TrimStart('/') ?? string.Empty}";
                }
            }
            CalculateRequestStatus(req);
        }
Example #7
0
        public void IssueNotificationTests_NoRequest()
        {
            var notificationOptions = new NotificationOptions
            {
                Substitutes = new Dictionary <string, string>
                {
                    { "IssueDescription", "Desc" },
                    { "IssueCategory", "Cat" },
                    { "IssueStatus", "state" },
                    { "IssueSubject", "sub" },
                    { "NewIssueComment", "a" },
                    { "IssueUser", "User" },
                    { "IssueUserAlias", "alias" },
                    { "RequestType", "Movie" },
                    { "PosterPath", "aaaaa" }
                }
            };

            var customization = new CustomizationSettings();
            var userPrefs     = new UserNotificationPreferences();

            sut.Setup(notificationOptions, (MovieRequests)null, customization, userPrefs);

            Assert.That("Desc", Is.EqualTo(sut.IssueDescription));
            Assert.That("Cat", Is.EqualTo(sut.IssueCategory));
            Assert.That("state", Is.EqualTo(sut.IssueStatus));
            Assert.That("a", Is.EqualTo(sut.NewIssueComment));
            Assert.That("User", Is.EqualTo(sut.UserName));
            Assert.That("alias", Is.EqualTo(sut.Alias));
            Assert.That("Movie", Is.EqualTo(sut.Type));
            Assert.That("https://image.tmdb.org/t/p/w300/aaaaa", Is.EqualTo(sut.PosterImage));
        }
        public void Setup(NotificationOptions opts, ChildRequests req, CustomizationSettings s,
                          UserNotificationPreferences pref)
        {
            LoadIssues(opts);
            LoadCommon(req, s, pref, opts);
            LoadTitle(opts, req);
            ProviderId            = req?.ParentRequest?.ExternalProviderId.ToString() ?? string.Empty;
            Year                  = req?.ParentRequest?.ReleaseDate.Year.ToString();
            Overview              = req?.ParentRequest?.Overview;
            AdditionalInformation = opts.AdditionalInformation;
            var img = req?.ParentRequest?.PosterPath ?? string.Empty;

            if (img.HasValue())
            {
                if (img.StartsWith("http"))
                {
                    // This means it's a legacy request from when we used TvMaze as a provider.
                    // The poster url is the fully qualified address, so just use it
                    PosterImage = img;
                }
                else
                {
                    PosterImage =
                        $"https://image.tmdb.org/t/p/w300/{img?.TrimStart('/') ?? string.Empty}";
                }
            }

            // Generate episode list.
            StringBuilder epSb = new StringBuilder();
            IEnumerable <EpisodeRequests> episodes = req?.SeasonRequests?
                                                     .SelectMany(x => x.Episodes) ?? new List <EpisodeRequests>();

            episodes
            .OrderBy(x => x.EpisodeNumber)
            .ToList()
            .ForEach(ep => epSb.Append($"{ep.EpisodeNumber},"));
            if (epSb.Length > 0)
            {
                epSb.Remove(epSb.Length - 1, 1);
            }
            EpisodesList = epSb.ToString();

            // Generate season list.
            StringBuilder         seasonSb = new StringBuilder();
            List <SeasonRequests> seasons  = req?.SeasonRequests ?? new List <SeasonRequests>();

            seasons
            .OrderBy(x => x.SeasonNumber)
            .ToList()
            .ForEach(ep => seasonSb.Append($"{ep.SeasonNumber},"));
            if (seasonSb.Length > 0)
            {
                seasonSb.Remove(seasonSb.Length - 1, 1);
            }
            SeasonsList = seasonSb.ToString();
            CalculateRequestStatus(req);
        }
        public void TvNotification_EpisodeList()
        {
            var episodeRequests = new List <EpisodeRequests>
            {
                new EpisodeRequests
                {
                    EpisodeNumber = 1,
                },
                new EpisodeRequests
                {
                    EpisodeNumber = 2,
                },
                new EpisodeRequests
                {
                    EpisodeNumber = 3,
                }
            };
            var seasonRequests = new List <SeasonRequests>
            {
                new SeasonRequests
                {
                    Episodes     = episodeRequests,
                    SeasonNumber = 1
                },
                new SeasonRequests
                {
                    Episodes     = episodeRequests,
                    SeasonNumber = 2
                },
                new SeasonRequests
                {
                    Episodes     = episodeRequests,
                    SeasonNumber = 3
                }
            };


            var notificationOptions = new NotificationOptions();
            var req = F.Build <ChildRequests>()
                      .With(x => x.RequestType, RequestType.TvShow)
                      .With(x => x.Available, true)
                      .With(x => x.SeasonRequests, seasonRequests)
                      .Create();
            var customization = new CustomizationSettings
            {
                ApplicationUrl  = "url",
                ApplicationName = "name"
            };
            var userPrefs = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);

            Assert.That(sut.EpisodesList, Is.EqualTo("1,1,1,2,2,2,3,3,3"));
            Assert.That(sut.SeasonsList, Is.EqualTo("1,2,3"));
        }
 public void Setup(NotificationOptions opts, AlbumRequest req, CustomizationSettings s,
                   UserNotificationPreferences pref)
 {
     LoadIssues(opts);
     LoadCommon(req, s, pref, opts);
     LoadTitle(opts, req);
     ProviderId            = req?.ForeignArtistId ?? string.Empty;
     Year                  = req?.ReleaseDate.Year.ToString();
     AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;
     PosterImage           = req?.Cover.HasValue() ?? false ? req.Cover : req?.Disk ?? string.Empty;
     CalculateRequestStatus(req);
 }
        public Task UpsertAsync(UserNotificationPreferences preferences)
        {
            var filter = Builders <UserNotificationPreferences> .Filter.Eq(v => v.Id, preferences.Id);

            var collection = GetCollection <UserNotificationPreferences>();

            return(RetryPolicy.ExecuteAsync(_ =>
                                            collection.ReplaceOneAsync(filter, preferences, new UpdateOptions {
                IsUpsert = true
            }),
                                            new Context(nameof(UpsertAsync))));
        }
        private UserSignedInCommandHandler GetSut(User user, UserNotificationPreferences preference)
        {
            _mockUserRepository.Setup(u => u.GetAsync(It.IsAny <string>())).ReturnsAsync(user);
            _mockUserNotificationPreferencesRepository.Setup(u => u.GetAsync(It.IsAny <string>())).ReturnsAsync(preference);

            return(new UserSignedInCommandHandler(
                       Mock.Of <ILogger <UserSignedInCommandHandler> >(),
                       _mockUserRepository.Object,
                       _mockUserNotificationPreferencesRepository.Object,
                       _mockTimeProvider.Object,
                       _mockQueueService.Object
                       ));
        }
Example #13
0
 public void Setup(NotificationOptions opts, MovieRequests req, CustomizationSettings s,
                   UserNotificationPreferences pref)
 {
     LoadIssues(opts);
     LoadCommon(req, s, pref);
     LoadTitle(opts, req);
     ProviderId            = req?.TheMovieDbId.ToString() ?? string.Empty;
     Year                  = req?.ReleaseDate.Year.ToString();
     Overview              = req?.Overview;
     AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;
     PosterImage           = $"https://image.tmdb.org/t/p/w300/{req?.PosterPath?.TrimStart('/') ?? string.Empty}";
     CalculateRequestStatus(req);
 }
        public string TvShowNotificationTests_RequestStatus(bool available, bool denied, bool approved)
        {
            var notificationOptions = new NotificationOptions();
            var req = F.Build <ChildRequests>()
                      .With(x => x.RequestType, RequestType.TvShow)
                      .With(x => x.Available, available)
                      .With(x => x.Denied, denied)
                      .With(x => x.Approved, approved)
                      .Create();
            var customization = new CustomizationSettings();
            var userPrefs     = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);
            return(sut.RequestStatus);
        }
        public async Task GiveAllTheTypesAreUnselectedAndPersistedPreferencesAreEmpty_ThenReturnValidationError()
        {
            var emptyPreferences = new UserNotificationPreferences()
            {
                NotificationTypes = NotificationTypes.None
            };

            _recruitVacancyClientMock.Setup(c => c.GetUserNotificationPreferencesAsync(It.IsAny <string>())).ReturnsAsync(emptyPreferences);
            var sut    = GetSut();
            var result = await sut.UpdateUserNotificationPreferencesAsync(new ManageNotificationsEditModel(), new VacancyUser());

            result.Errors.HasErrors.Should().BeTrue();
            result.Errors.Errors.Count.Should().Be(1);
            result.Errors.Errors.First().ErrorMessage.Should().Be("Choose when you’d like to receive emails");
        }
        private void LoadCommon(BaseRequest req, CustomizationSettings s, UserNotificationPreferences pref, NotificationOptions opts)
        {
            ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s.ApplicationName;
            ApplicationUrl  = s?.ApplicationUrl.HasValue() ?? false ? s.ApplicationUrl : string.Empty;
            AvailableDate   = req?.MarkedAsAvailable?.ToString("D") ?? string.Empty;
            DenyReason      = req?.DeniedReason;
            RequestId       = req?.Id.ToString();
            RequestedUser   = req?.RequestedUser?.UserName;
            RequestedDate   = req?.RequestedDate.ToString("D");
            DetailsUrl      = GetDetailsUrl(s, req);

            if (Type.IsNullOrEmpty())
            {
                Type = HumanizeReturnType(req?.RequestType);
            }

            if (UserName.IsNullOrEmpty())
            {
                UserName = req?.RequestedUser?.UserName;
            }

            if (Alias.IsNullOrEmpty())
            {
                Alias = req?.RequestedUser?.Alias.HasValue() ?? false
                    ? req.RequestedUser?.Alias
                    : req?.RequestedUser?.UserName;
            }

            if (pref != null)
            {
                UserPreference = pref.Value.HasValue() ? pref.Value : Alias;
            }

            if (opts.NotificationType == NotificationType.PartiallyAvailable)
            {
                if (opts.Substitutes.TryGetValue("Season", out var sNumber))
                {
                    PartiallyAvailableSeasonNumber = sNumber;
                }
                if (opts.Substitutes.TryGetValue("Episodes", out var epNumber))
                {
                    PartiallyAvailableEpisodeNumbers = epNumber;
                }
            }
        }
Example #17
0
        public void Setup(NotificationOptions opts, ChildRequests req, CustomizationSettings s,
                          UserNotificationPreferences pref)
        {
            LoadIssues(opts);
            LoadCommon(req, s, pref);
            LoadTitle(opts, req);
            ProviderId            = req?.ParentRequest?.ExternalProviderId.ToString() ?? string.Empty;
            Year                  = req?.ParentRequest?.ReleaseDate.Year.ToString();
            Overview              = req?.ParentRequest?.Overview;
            AdditionalInformation = opts.AdditionalInformation;
            PosterImage           =
                $"https://image.tmdb.org/t/p/w300/{req?.ParentRequest?.PosterPath?.TrimStart('/') ?? string.Empty}";

            // Generate episode list.
            StringBuilder epSb = new StringBuilder();
            IEnumerable <EpisodeRequests> episodes = req?.SeasonRequests?
                                                     .SelectMany(x => x.Episodes) ?? new List <EpisodeRequests>();

            episodes
            .OrderBy(x => x.EpisodeNumber)
            .ToList()
            .ForEach(ep => epSb.Append($"{ep.EpisodeNumber},"));
            if (epSb.Length > 0)
            {
                epSb.Remove(epSb.Length - 1, 1);
            }
            EpisodesList = epSb.ToString();

            // Generate season list.
            StringBuilder         seasonSb = new StringBuilder();
            List <SeasonRequests> seasons  = req?.SeasonRequests ?? new List <SeasonRequests>();

            seasons
            .OrderBy(x => x.SeasonNumber)
            .ToList()
            .ForEach(ep => seasonSb.Append($"{ep.SeasonNumber},"));
            if (seasonSb.Length > 0)
            {
                seasonSb.Remove(seasonSb.Length - 1, 1);
            }
            SeasonsList = seasonSb.ToString();
            CalculateRequestStatus(req);
        }
Example #18
0
        public void TvNotificationPartialAvailablilityTests()
        {
            var notificationOptions = new NotificationOptions {
                NotificationType = Helpers.NotificationType.PartiallyAvailable
            };

            notificationOptions.Substitutes.Add("Season", "1");
            notificationOptions.Substitutes.Add("Episodes", "1, 2");
            var req = F.Build <ChildRequests>()
                      .With(x => x.RequestType, RequestType.TvShow)
                      .With(x => x.Available, true)
                      .Create();
            var customization = new CustomizationSettings
            {
                ApplicationUrl  = "url",
                ApplicationName = "name"
            };
            var userPrefs = new UserNotificationPreferences();

            sut.Setup(notificationOptions, req, customization, userPrefs);

            Assert.That(req.Id.ToString(), Is.EqualTo(sut.RequestId));
            Assert.That(req.ParentRequest.ExternalProviderId.ToString(), Is.EqualTo(sut.ProviderId));
            Assert.That(req.ParentRequest.Title.ToString(), Is.EqualTo(sut.Title));
            Assert.That(req.RequestedUser.UserName, Is.EqualTo(sut.RequestedUser));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.Alias));
            Assert.That(req.RequestedDate.ToString("D"), Is.EqualTo(sut.RequestedDate));
            Assert.That("TV Show", Is.EqualTo(sut.Type));
            Assert.That(req.ParentRequest.Overview, Is.EqualTo(sut.Overview));
            Assert.That(req.ParentRequest.ReleaseDate.Year.ToString(), Is.EqualTo(sut.Year));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.MarkedAsAvailable?.ToString("D"), Is.EqualTo(sut.AvailableDate));
            Assert.That("https://image.tmdb.org/t/p/w300/" + req.ParentRequest.PosterPath, Is.EqualTo(sut.PosterImage));
            Assert.That(req.DeniedReason, Is.EqualTo(sut.DenyReason));
            Assert.That(req.RequestedUser.Alias, Is.EqualTo(sut.UserPreference));
            Assert.That(null, Is.EqualTo(sut.AdditionalInformation));
            Assert.That("Available", Is.EqualTo(sut.RequestStatus));
            Assert.That("url", Is.EqualTo(sut.ApplicationUrl));
            Assert.That("name", Is.EqualTo(sut.ApplicationName));
            Assert.That(sut.PartiallyAvailableEpisodeNumbers, Is.EqualTo("1, 2"));
            Assert.That(sut.PartiallyAvailableSeasonNumber, Is.EqualTo("1"));
        }
        public void MovieNotificationUserPreferences()
        {
            var notificationOptions = new NotificationOptions
            {
                AdditionalInformation = "add"
            };
            var req = F.Build <MovieRequests>()
                      .With(x => x.RequestType, RequestType.Movie)
                      .Without(x => x.MarkedAsAvailable)
                      .Create();
            var customization = new CustomizationSettings();
            var userPrefs     = new UserNotificationPreferences
            {
                Value = "PrefValue"
            };

            sut.Setup(notificationOptions, req, customization, userPrefs);

            Assert.That("PrefValue", Is.EqualTo(sut.UserPreference));
            Assert.That(string.Empty, Is.EqualTo(sut.AvailableDate));
            Assert.That("add", Is.EqualTo(sut.AdditionalInformation));
        }
Example #20
0
        public void Setup(NotificationOptions opts, AlbumRequest req, CustomizationSettings s, UserNotificationPreferences pref)
        {
            LoadIssues(opts);

            RequestId = req?.Id.ToString();

            string title;

            if (req == null)
            {
                opts.Substitutes.TryGetValue("Title", out title);
            }
            else
            {
                title = req?.Title;
            }
            ApplicationUrl  = (s?.ApplicationUrl.HasValue() ?? false) ? s.ApplicationUrl : string.Empty;
            ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s?.ApplicationName;
            RequestedUser   = req?.RequestedUser?.UserName;
            if (UserName.IsNullOrEmpty())
            {
                // Can be set if it's an issue
                UserName = req?.RequestedUser?.UserName;
            }

            AvailableDate = req?.MarkedAsAvailable?.ToString("D") ?? string.Empty;
            DenyReason    = req?.DeniedReason;
            Alias         = (req?.RequestedUser?.Alias.HasValue() ?? false) ? req?.RequestedUser?.Alias : req?.RequestedUser?.UserName;
            if (pref != null)
            {
                UserPreference = pref.Value.HasValue() ? pref.Value : Alias;
            }
            Title         = title;
            RequestedDate = req?.RequestedDate.ToString("D");
            if (Type.IsNullOrEmpty())
            {
                Type = req?.RequestType.Humanize();
            }
            Year        = req?.ReleaseDate.Year.ToString();
            PosterImage = (req?.Cover.HasValue() ?? false) ? req.Cover : req?.Disk ?? string.Empty;

            AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;
        }
Example #21
0
        public void Setup(NotificationOptions opts, FullBaseRequest req, CustomizationSettings s, UserNotificationPreferences pref)
        {
            LoadIssues(opts);

            RequestId = req?.Id.ToString();

            string title;

            if (req == null)
            {
                opts.Substitutes.TryGetValue("Title", out title);
            }
            else
            {
                title = req?.Title;
            }
            ApplicationUrl  = (s?.ApplicationUrl.HasValue() ?? false) ? s.ApplicationUrl : string.Empty;
            ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s?.ApplicationName;
            RequestedUser   = req?.RequestedUser?.UserName;
            if (UserName.IsNullOrEmpty())
            {
                // Can be set if it's an issue
                UserName = req?.RequestedUser?.UserName;
            }

            Alias = (req?.RequestedUser?.Alias.HasValue() ?? false) ? req?.RequestedUser?.Alias : req?.RequestedUser?.UserName;
            if (pref != null)
            {
                UserPreference = pref.Value.HasValue() ? pref.Value : Alias;
            }
            Title         = title;
            RequestedDate = req?.RequestedDate.ToString("D");
            if (Type.IsNullOrEmpty())
            {
                Type = req?.RequestType.Humanize();
            }
            Overview      = req?.Overview;
            Year          = req?.ReleaseDate.Year.ToString();
            DenyReason    = req?.DeniedReason;
            AvailableDate = req?.MarkedAsAvailable?.ToString("D") ?? string.Empty;
            if (req?.RequestType == RequestType.Movie)
            {
                PosterImage = string.Format((req?.PosterPath ?? string.Empty).StartsWith("/", StringComparison.InvariantCultureIgnoreCase)
                    ? "https://image.tmdb.org/t/p/w300{0}" : "https://image.tmdb.org/t/p/w300/{0}", req?.PosterPath);
            }
            else
            {
                PosterImage = req?.PosterPath;
            }

            AdditionalInformation = opts?.AdditionalInformation ?? string.Empty;
        }
Example #22
0
        public void Setup(NotificationOptions opts, ChildRequests req, CustomizationSettings s, UserNotificationPreferences pref)
        {
            LoadIssues(opts);

            RequestId = req?.ParentRequestId.ToString();

            string title;

            if (req == null)
            {
                opts.Substitutes.TryGetValue("Title", out title);
            }
            else
            {
                title = req?.ParentRequest.Title;
            }
            DenyReason      = req?.DeniedReason;
            ApplicationUrl  = (s?.ApplicationUrl.HasValue() ?? false) ? s.ApplicationUrl : string.Empty;
            ApplicationName = string.IsNullOrEmpty(s?.ApplicationName) ? "Ombi" : s?.ApplicationName;
            RequestedUser   = req?.RequestedUser?.UserName;
            if (UserName.IsNullOrEmpty())
            {
                // Can be set if it's an issue
                UserName = req?.RequestedUser?.UserName;
            }
            AvailableDate = req?.MarkedAsAvailable?.ToString("D") ?? string.Empty;
            Alias         = (req?.RequestedUser?.Alias.HasValue() ?? false) ? req?.RequestedUser?.Alias : req?.RequestedUser?.UserName;
            if (pref != null)
            {
                UserPreference = pref.Value.HasValue() ? pref.Value : Alias;
            }
            Title         = title;
            RequestedDate = req?.RequestedDate.ToString("D");
            if (Type.IsNullOrEmpty())
            {
                Type = req?.RequestType.Humanize();
            }

            Overview = req?.ParentRequest.Overview;
            Year     = req?.ParentRequest.ReleaseDate.Year.ToString();
            if (req?.RequestType == RequestType.Movie)
            {
                PosterImage = string.Format((req?.ParentRequest.PosterPath ?? string.Empty).StartsWith("/", StringComparison.InvariantCultureIgnoreCase)
                    ? "https://image.tmdb.org/t/p/w300{0}" : "https://image.tmdb.org/t/p/w300/{0}", req?.ParentRequest.PosterPath);
            }
            else
            {
                PosterImage = req?.ParentRequest.PosterPath;
            }
            AdditionalInformation = opts.AdditionalInformation;
            // DO Episode and Season Lists

            var episodes        = req?.SeasonRequests?.SelectMany(x => x.Episodes) ?? new List <EpisodeRequests>();
            var seasons         = req?.SeasonRequests?.OrderBy(x => x.SeasonNumber).ToList() ?? new List <SeasonRequests>();
            var orderedEpisodes = episodes.OrderBy(x => x.EpisodeNumber).ToList();
            var epSb            = new StringBuilder();
            var seasonSb        = new StringBuilder();

            for (var i = 0; i < orderedEpisodes.Count; i++)
            {
                var ep = orderedEpisodes[i];
                if (i < orderedEpisodes.Count - 1)
                {
                    epSb.Append($"{ep.EpisodeNumber},");
                }
                else
                {
                    epSb.Append($"{ep.EpisodeNumber}");
                }
            }

            for (var i = 0; i < seasons.Count; i++)
            {
                var ep = seasons[i];
                if (i < seasons.Count - 1)
                {
                    seasonSb.Append($"{ep.SeasonNumber},");
                }
                else
                {
                    seasonSb.Append($"{ep.SeasonNumber}");
                }
            }

            EpisodesList = epSb.ToString();
            SeasonsList  = seasonSb.ToString();
        }
Example #23
0
 protected UserNotificationPreferences GetUserPreference(string userId, NotificationAgent agent)
 {
     return(UserNotificationPreferences.GetAll()
            .FirstOrDefault(x => x.Agent == agent && x.UserId == userId));
 }
 private void SetPreferencesForVacancyRejectedNotification(CommunicationUserPreference userPref, UserNotificationPreferences userPreference)
 {
     if (userPreference == null)
     {
         return;
     }
     if (userPreference.NotificationTypes.HasFlag(NotificationTypes.VacancyRejected))
     {
         userPref.Channels  = DeliveryChannelPreferences.EmailOnly;
         userPref.Frequency = DeliveryFrequency.Immediate;
         userPref.Scope     = userPreference.NotificationScope.GetValueOrDefault().ConvertToCommunicationScope();
     }
 }
 private void SetPreferencesForApplicationSubmittedNotification(CommunicationUserPreference userPref, UserNotificationPreferences userPreference)
 {
     if (userPreference == null)
     {
         return;
     }
     if (userPreference.NotificationTypes.HasFlag(NotificationTypes.ApplicationSubmitted))
     {
         userPref.Channels  = DeliveryChannelPreferences.EmailOnly;
         userPref.Frequency = userPreference.NotificationFrequency.GetDeliveryFrequencyPreferenceFromUserFrequencyPreference();
         userPref.Scope     = userPreference.NotificationScope.GetValueOrDefault().ConvertToCommunicationScope();
     }
 }
        public EntityValidationResult ValidateUserNotificationPreferences(UserNotificationPreferences preferences)
        {
            var fluentResult = _userNotificationPreferencesValidator.Validate(preferences);

            return(EntityValidationResult.FromFluentValidationResult(fluentResult));
        }
Example #27
0
 private void SetPreferencesForVacancySentForReviewNotification(CommunicationUserPreference userPref, UserNotificationPreferences userPreference)
 {
     if (userPreference == null)
     {
         return;
     }
     if (userPreference.NotificationTypes.HasFlag(NotificationTypes.VacancySentForReview))
     {
         userPref.Channels  = DeliveryChannelPreferences.EmailOnly;
         userPref.Frequency = DeliveryFrequency.Immediate;
         userPref.Scope     = NotificationScope.Organisation;
     }
 }