Пример #1
0
        public async Task <Movie> AddMovie(string imdbId, QualityType desiredQuality)
        {
            Movie movie = _mediaCollectionContext.Movies.FirstOrDefault(m => m.ImdbId == imdbId);

            if (movie != null)
            {
                movie.DesiredQuality = desiredQuality;
            }
            else
            {
                try
                {
                    var metadata = await _omdbClient.GetMetadataByImdbId(imdbId);

                    movie = new Movie()
                    {
                        Title          = metadata.Title,
                        Plot           = metadata.Plot,
                        ImdbId         = imdbId,
                        Year           = Convert.ToInt32(metadata.Year),
                        Poster         = metadata.Poster,
                        Rating         = metadata.imdbRating,
                        inLibrary      = false,
                        DesiredQuality = desiredQuality
                    };

                    await _mediaCollectionContext.AddAsync(movie);
                }
                catch (Exception e)
                {
                    throw e;
                }
            }

            await _mediaCollectionContext.SaveChangesAsync();

            return(movie);
        }