Ejemplo n.º 1
0
        /// <summary>
        /// Requests the movie.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public async Task <RequestEngineResult> RequestMovie(MovieRequestViewModel model)
        {
            var movieInfo = await MovieApi.GetMovieInformationWithExtraInfo(model.TheMovieDbId);

            if (movieInfo == null || movieInfo.Id == 0)
            {
                return(new RequestEngineResult
                {
                    Result = false,
                    Message = "There was an issue adding this movie!",
                    ErrorMessage = $"Please try again later"
                });
            }
            var fullMovieName =
                $"{movieInfo.Title}{(!string.IsNullOrEmpty(movieInfo.ReleaseDate) ? $" ({DateTime.Parse(movieInfo.ReleaseDate).Year})" : string.Empty)}";

            var userDetails = await GetUser();

            var requestModel = new MovieRequests
            {
                TheMovieDbId = movieInfo.Id,
                RequestType  = RequestType.Movie,
                Overview     = movieInfo.Overview,
                ImdbId       = movieInfo.ImdbId,
                PosterPath   = PosterPathHelper.FixPosterPath(movieInfo.PosterPath),
                Title        = movieInfo.Title,
                ReleaseDate  = !string.IsNullOrEmpty(movieInfo.ReleaseDate)
                    ? DateTime.Parse(movieInfo.ReleaseDate)
                    : DateTime.MinValue,
                Status          = movieInfo.Status,
                RequestedDate   = DateTime.UtcNow,
                Approved        = false,
                RequestedUserId = userDetails.Id,
                Background      = movieInfo.BackdropPath
            };

            var usDates = movieInfo.ReleaseDates?.Results?.FirstOrDefault(x => x.IsoCode == "US");

            requestModel.DigitalReleaseDate = usDates?.ReleaseDate?.FirstOrDefault(x => x.Type == ReleaseDateType.Digital)?.ReleaseDate;

            var ruleResults = (await RunRequestRules(requestModel)).ToList();

            if (ruleResults.Any(x => !x.Success))
            {
                return(new RequestEngineResult
                {
                    ErrorMessage = ruleResults.FirstOrDefault(x => x.Message.HasValue()).Message
                });
            }

            if (requestModel.Approved) // The rules have auto approved this
            {
                var requestEngineResult = await AddMovieRequest(requestModel, fullMovieName);

                if (requestEngineResult.Result)
                {
                    var result = await ApproveMovie(requestModel);

                    if (result.IsError)
                    {
                        Logger.LogWarning("Tried auto sending movie but failed. Message: {0}", result.Message);
                        return(new RequestEngineResult
                        {
                            Message = result.Message,
                            ErrorMessage = result.Message,
                            Result = false
                        });
                    }

                    return(requestEngineResult);
                }

                // If there are no providers then it's successful but movie has not been sent
            }

            return(await AddMovieRequest(requestModel, fullMovieName));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Requests the movie.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <returns></returns>
        public async Task <RequestEngineResult> RequestMovie(MovieRequestViewModel model)
        {
            var movieInfo = await MovieApi.GetMovieInformationWithExtraInfo(model.TheMovieDbId, model.LanguageCode);

            if (movieInfo == null || movieInfo.Id == 0)
            {
                return(new RequestEngineResult
                {
                    Result = false,
                    Message = "There was an issue adding this movie!",
                    ErrorMessage = $"Please try again later"
                });
            }

            var fullMovieName =
                $"{movieInfo.Title}{(!string.IsNullOrEmpty(movieInfo.ReleaseDate) ? $" ({DateTime.Parse(movieInfo.ReleaseDate).Year})" : string.Empty)}";

            var userDetails = await GetUser();

            var canRequestOnBehalf = model.RequestOnBehalf.HasValue();

            var isAdmin = await UserManager.IsInRoleAsync(userDetails, OmbiRoles.PowerUser) ||
                          await UserManager.IsInRoleAsync(userDetails, OmbiRoles.Admin);

            if (canRequestOnBehalf && !isAdmin)
            {
                return(new RequestEngineResult
                {
                    Result = false,
                    Message = "You do not have the correct permissions to request on behalf of users!",
                    ErrorMessage = $"You do not have the correct permissions to request on behalf of users!"
                });
            }

            if ((model.RootFolderOverride.HasValue || model.QualityPathOverride.HasValue) && !isAdmin)
            {
                return(new RequestEngineResult
                {
                    Result = false,
                    Message = "You do not have the correct permissions!",
                    ErrorMessage = $"You do not have the correct permissions!"
                });
            }

            var is4kFeatureEnabled = await _featureService.FeatureEnabled(FeatureNames.Movie4KRequests);

            var is4kRequest = is4kFeatureEnabled && model.Is4kRequest;

            MovieRequests requestModel;
            bool          isExisting = false;
            // Do we already have a request? 4k or non 4k
            var existingRequest = await MovieRepository.GetRequestAsync(movieInfo.Id);

            if (existingRequest != null && is4kFeatureEnabled)
            {
                if (model.Is4kRequest)
                {
                    existingRequest.Is4kRequest     = true;
                    existingRequest.RequestedDate4k = DateTime.Now;
                }
                else
                {
                    existingRequest.RequestedDate = DateTime.Now;
                }
                isExisting   = true;
                requestModel = existingRequest;
            }
            else
            {
                requestModel = new MovieRequests
                {
                    TheMovieDbId = movieInfo.Id,
                    RequestType  = RequestType.Movie,
                    Overview     = movieInfo.Overview,
                    ImdbId       = movieInfo.ImdbId,
                    PosterPath   = PosterPathHelper.FixPosterPath(movieInfo.PosterPath),
                    Title        = movieInfo.Title,
                    ReleaseDate  = !string.IsNullOrEmpty(movieInfo.ReleaseDate)
                        ? DateTime.Parse(movieInfo.ReleaseDate)
                        : DateTime.MinValue,
                    Status           = movieInfo.Status,
                    RequestedDate    = model.Is4kRequest ? DateTime.MinValue : DateTime.Now,
                    Approved         = false,
                    RequestedUserId  = canRequestOnBehalf ? model.RequestOnBehalf : userDetails.Id,
                    Background       = movieInfo.BackdropPath,
                    LangCode         = model.LanguageCode,
                    RequestedByAlias = model.RequestedByAlias,
                    RootPathOverride = model.RootFolderOverride.GetValueOrDefault(),
                    QualityOverride  = model.QualityPathOverride.GetValueOrDefault(),
                    RequestedDate4k  = model.Is4kRequest ? DateTime.Now : DateTime.MinValue,
                    Is4kRequest      = model.Is4kRequest,
                    Source           = model.Source
                };
            }

            var usDates = movieInfo.ReleaseDates?.Results?.FirstOrDefault(x => x.IsoCode == "US");

            requestModel.DigitalReleaseDate = usDates?.ReleaseDate
                                              ?.FirstOrDefault(x => x.Type == ReleaseDateType.Digital)?.ReleaseDate;

            var ruleResults       = (await RunRequestRules(requestModel)).ToList();
            var ruleResultInError = ruleResults.Find(x => !x.Success);

            if (ruleResultInError != null)
            {
                return(new RequestEngineResult
                {
                    ErrorMessage = ruleResultInError.Message,
                    ErrorCode = ruleResultInError.ErrorCode
                });
            }

            if (requestModel.Approved) // The rules have auto approved this
            {
                var requestEngineResult = await AddMovieRequest(requestModel, fullMovieName, model.RequestOnBehalf, isExisting, is4kRequest);

                if (requestEngineResult.Result)
                {
                    var result = await ApproveMovie(requestModel, model.Is4kRequest);

                    if (result.IsError)
                    {
                        Logger.LogWarning("Tried auto sending movie but failed. Message: {0}", result.Message);
                        return(new RequestEngineResult
                        {
                            Message = result.Message,
                            ErrorMessage = result.Message,
                            Result = false
                        });
                    }

                    return(requestEngineResult);
                }

                // If there are no providers then it's successful but movie has not been sent
            }

            return(await AddMovieRequest(requestModel, fullMovieName, model.RequestOnBehalf, isExisting, is4kRequest));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Gets the requests.
        /// </summary>
        /// <param name="count">The count.</param>
        /// <param name="position">The position.</param>
        /// <param name="orderFilter">The order/filter type.</param>
        /// <returns></returns>
        public async Task <RequestsViewModel <MovieRequests> > GetRequests(int count, int position,
                                                                           OrderFilterModel orderFilter)
        {
            var shouldHide = await HideFromOtherUsers();

            IQueryable <MovieRequests> allRequests;

            if (shouldHide.Hide)
            {
                allRequests =
                    MovieRepository.GetWithUser(shouldHide
                                                .UserId); //.Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync();
            }
            else
            {
                allRequests =
                    MovieRepository
                    .GetWithUser();     //.Skip(position).Take(count).OrderByDescending(x => x.ReleaseDate).ToListAsync();
            }

            switch (orderFilter.AvailabilityFilter)
            {
            case FilterType.None:
                break;

            case FilterType.Available:
                allRequests = allRequests.Where(x => x.Available);
                break;

            case FilterType.NotAvailable:
                allRequests = allRequests.Where(x => !x.Available);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            switch (orderFilter.StatusFilter)
            {
            case FilterType.None:
                break;

            case FilterType.Approved:
                allRequests = allRequests.Where(x => x.Approved);
                break;

            case FilterType.Processing:
                allRequests = allRequests.Where(x => x.Approved && !x.Available);
                break;

            case FilterType.PendingApproval:
                allRequests = allRequests.Where(x => !x.Approved && !x.Available && !(x.Denied ?? false));
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var total = allRequests.Count();

            var requests = await(OrderMovies(allRequests, orderFilter.OrderType)).Skip(position).Take(count)
                           .ToListAsync();

            requests.ForEach(async x =>
            {
                x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath);
                await CheckForSubscription(shouldHide, x);
            });
            return(new RequestsViewModel <MovieRequests>
            {
                Collection = requests,
                Total = total
            });
        }
Ejemplo n.º 4
0
 public string PostPathTest(string posterPath)
 {
     return(PosterPathHelper.FixPosterPath(posterPath));
 }