Ejemplo n.º 1
0
        public ActionResult GetEpisodes(int id, string title)
        {
            if (!Settings.HasSettings)
            {
                ViewBag.Error = Resources.Resources.Settings_Missing_Sonarr;
                return PartialView("DashletError");
            }

            var formattedUri = UrlHelper.ReturnUri(Settings.IpAddress, Settings.Port).ToString();

            var episodes = ApiService.GetSonarrEpisodes(formattedUri, Settings.ApiKey, id);
            var viewModel = new SonarrEpisodeViewModel { EpisodeViewModels = new Dictionary<int, List<EpisodeViewModel>>(), SeasonTitle = title };

            foreach (var e in episodes)
            {
                var episodeViewModel = new EpisodeViewModel();

                if (!viewModel.EpisodeViewModels.ContainsKey(e.seasonNumber))
                {
                    viewModel.EpisodeViewModels.Add(e.seasonNumber, new List<EpisodeViewModel>());
                }
                var mappedResult = (EpisodeViewModel)episodeViewModel.InjectFrom(new SonarrEpisodeMapper(), e);
                viewModel.EpisodeViewModels[e.seasonNumber].Add(mappedResult);

            }

            return PartialView("Episodes", viewModel);
        }
Ejemplo n.º 2
0
        public void SonarrEpisodeMapper(int id, int seriesId, int epiNum, string airDate, string airDateUtc, bool downloading,
           int episodeFileId, int episodenumber, bool hasfile, bool monitoredBool, string overView, int sceneEpiNumber,
            int sceneSeasonNum, int seasonNum, string titleString, int tvdbId)
        {
            var source = new SonarrEpisode
            {
                id = id,
                seriesId = seriesId,
                absoluteEpisodeNumber = epiNum,
                airDate = airDate,
                airDateUtc = airDateUtc,
                downloading = downloading,
                episodeFileId = episodeFileId,
                episodeNumber = episodenumber,
                hasFile = hasfile,
                monitored = monitoredBool,
                overview = overView,
                sceneEpisodeNumber = sceneEpiNumber,
                sceneSeasonNumber = sceneSeasonNum,
                seasonNumber = seasonNum,
                title = titleString,
                tvDbEpisodeId = tvdbId
            };

            var target = new EpisodeViewModel();
            target.InjectFrom(new SonarrEpisodeMapper(), source);

            Assert.That(target.ID, Is.EqualTo(id));
            Assert.That(target.SeriesId, Is.EqualTo(seriesId));
            Assert.That(target.AbsoluteEpisodeNumber, Is.EqualTo(epiNum));
            Assert.That(target.AirDate, Is.EqualTo(new DateTime(2009,09,17)));
            Assert.That(target.AirDateUtc, Is.EqualTo(new DateTime(2009,09,18,03,00,00)));
            Assert.That(target.Downloading, Is.EqualTo(downloading));
            Assert.That(target.EpisodeFileId, Is.EqualTo(episodeFileId));
            Assert.That(target.EpisodeNumber, Is.EqualTo(episodenumber));
            Assert.That(target.HasFile, Is.EqualTo(hasfile));
            Assert.That(target.Monitored, Is.EqualTo(monitoredBool));
            Assert.That(target.Overview, Is.EqualTo(overView));
            Assert.That(target.SceneEpisodeNumber, Is.EqualTo(sceneEpiNumber));
            Assert.That(target.SceneSeasonNumber, Is.EqualTo(sceneSeasonNum));
            Assert.That(target.SeasonNumber, Is.EqualTo(seasonNum));
            Assert.That(target.Title, Is.EqualTo(titleString));
            Assert.That(target.TvDbEpisodeId, Is.EqualTo(tvdbId));
        }