Esempio n. 1
0
        private async Task ProcessMovies()
        {
            // Get all non available
            var movies = _movieRepo.GetAll().Include(x => x.RequestedUser).Where(x => !x.Available).AsNoTracking();
            var itemsForAvailbility = new List <AvailabilityModel>();

            foreach (var movie in movies)
            {
                if (movie.Available)
                {
                    return;
                }

                PlexServerContent item = null;
                if (movie.ImdbId.HasValue())
                {
                    item = await _repo.Get(movie.ImdbId);
                }
                if (item == null)
                {
                    if (movie.TheMovieDbId.ToString().HasValue())
                    {
                        item = await _repo.Get(movie.TheMovieDbId.ToString());
                    }
                }
                if (item == null)
                {
                    // We don't yet have this
                    continue;
                }

                _log.LogInformation("[PAC] - Movie request {0} is now available, sending notification", $"{movie.Title} - {movie.Id}");
                itemsForAvailbility.Add(new AvailabilityModel
                {
                    Id            = movie.Id,
                    RequestedUser = movie.RequestedUser != null ? movie.RequestedUser.Email : string.Empty
                });
            }

            foreach (var i in itemsForAvailbility)
            {
                await _movieRepo.MarkAsAvailable(i.Id);

                await _notificationService.Notify(new NotificationOptions
                {
                    DateTime         = DateTime.Now,
                    NotificationType = NotificationType.RequestAvailable,
                    RequestId        = i.Id,
                    RequestType      = RequestType.Movie,
                    Recipient        = i.RequestedUser
                });
            }

            await _repo.SaveChangesAsync();
        }