Exemplo n.º 1
0
        public async Task <IActionResult> AddSeries(AddSeriesViewModel addSeries)
        {
            Media media = _context.Medias.SingleOrDefault(m => m.ImdbId == addSeries.ImdbId);

            if (media == null)
            {
                MediaType mediaType = _context.MediaTypes.SingleOrDefault(m => m.Name == SpinningFilmHelper.SeriesType);

                string responseBody = await _apiService.GetWithCreditsAsync(addSeries.TmdbId, SpinningFilmHelper.SeriesType);

                TmdbTVResult tvResult = JsonConvert.DeserializeObject <TmdbTVResult>(responseBody);

                responseBody = await _apiService.GetOmdbResult(addSeries.ImdbId);

                RatingResult ratingResult = JsonConvert.DeserializeObject <RatingResult>(responseBody);

                media = new Media(tvResult, mediaType, ratingResult, addSeries.ImdbId);
                _context.Add(media);

                Series series = new Series(tvResult, media.MediaId);
                _context.Add(series);

                List <Genre> dbGenres = _context.Genres.ToList();
                foreach (var item in tvResult.Genres)
                {
                    var        genre      = dbGenres.SingleOrDefault(g => g.GenreId == item.GenreId) ?? _context.Genres.Add(item).Entity;
                    MediaGenre mediaGenre = new MediaGenre(media.MediaId, genre);
                    _context.Add(mediaGenre);
                }

                tvResult.Credits.Cast.ForEach(c => c.MediaId = media.MediaId);
                _context.Casts.AddRange(tvResult.Credits.Cast);

                tvResult.Credits.Crew.ForEach(c => c.MediaId = media.MediaId);
                _context.Crews.AddRange(tvResult.Credits.Crew);

                _context.SaveChanges();
            }

            if (!_context.PhysicalMedias.Any(m => m.AppUserId == User.Identity.GetNameIdGuid() && m.MediaId == media.MediaId))
            {
                foreach (var number in addSeries.SeasonNumbers)
                {
                    var physicalMedia = addSeries.PhysicalMedias[number - 1];
                    physicalMedia.MediaId   = media.MediaId;
                    physicalMedia.AppUserId = User.Identity.GetNameIdGuid();
                    _context.PhysicalMedias.Add(physicalMedia);

                    PhysicalSeason physicalSeason = new PhysicalSeason(physicalMedia.PhysicalMediaId, number);
                    _context.PhysicalSeasons.Add(physicalSeason);
                }

                _context.SaveChanges();

                return(View("AddMedia", media));
            }

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 2
0
 public Series(TmdbTVResult media, Guid mediaId)
 {
     SeriesId        = Guid.NewGuid();
     MediaId         = mediaId;
     NumberOfSeasons = media.NumberOfSeasons;
     FirstAired      = media.FirstAired;
     LastAired       = media.LastAired;
 }
Exemplo n.º 3
0
 public Media(TmdbTVResult media, MediaType mediaType, RatingResult rating, string imdbId)
 {
     MediaId     = Guid.NewGuid();
     MediaTypeId = mediaType.MediaTypeId;
     ImdbId      = imdbId;
     TmdbId      = media.TmdbId;
     Title       = media.Name;
     Poster      = media.Poster;
     ImdbRating  = rating.ImdbRating;
     Rated       = rating.Rated;
     Metascore   = rating.Metascore;
     PlotShort   = rating.Plot;
     PlotLong    = media.Plot;
 }
Exemplo n.º 4
0
        public async Task <IActionResult> AddSeriesModal(AddSeriesViewModel addSeries)
        {
            string responseBody = await _apiService.GetWithExternalIdsAsync(addSeries.TmdbId, SpinningFilmHelper.SeriesType);

            TmdbTVResult result = JsonConvert.DeserializeObject <TmdbTVResult>(responseBody);

            addSeries.ImdbId          = result.ExternalIds.ImdbId;
            addSeries.Title           = result.Name;
            addSeries.DiscTypes       = _context.DiscTypes.ToList();
            addSeries.Poster          = TmdbSettings.PosterSmall + result.Poster;
            addSeries.NumberOfSeasons = result.NumberOfSeasons;

            Media media = _context.Medias.SingleOrDefault(m => m.ImdbId == addSeries.ImdbId) ?? new Media();

            Guid userId = User.Identity.GetNameIdGuid();

            for (int i = 0; i < addSeries.NumberOfSeasons; i++)
            {
                addSeries.PhysicalMedias.Add(new PhysicalMedia(media.MediaId, userId));
            }

            return(View(addSeries));
        }