コード例 #1
0
 public IActionResult Create(TvProgram tvProgram)
 {
     if (ModelState.IsValid) {
         _context.TvPrograms.Add(tvProgram);
         _context.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(tvProgram);
 }
コード例 #2
0
ファイル: TvDataContext.cs プロジェクト: olliholliday/TvList
        protected TvProgram GetOrCreateTvProgramFromListingInfo(IAddTvBroadCastListingInfo info)
        {
            // find or create a TvProgram with the same Title.
            // This is overly eager to match and should be comparing previous broadcasts on this channel or from this source maybe.
            var program = FindExistingProgramByTitle(info.ProgramTitle);
            if (program == null) {

                // no program found - create a new one
                program = new TvProgram {
                    ProgramTitle = info.ProgramTitle
                };
                TvPrograms.Add(program);

            }

            return program;
        }
コード例 #3
0
ファイル: TvDataContext.cs プロジェクト: olliholliday/TvList
        /// <summary>
        /// Locates an existing TvEpisode by series and episode number match
        /// </summary>
        /// <param name="episodeTitle"></param>
        /// <returns></returns>
        protected TvProgramEpisode FindExistingEpisodeByNumber(TvProgram program, int? seriesNumber, int? episodeNumber)
        {
            if (program.TvProgramId == 0) {
                return null;
            }

            var local = ChangeTracker.Entries<TvProgramEpisode>().FirstOrDefault(x =>
                x.Property(y => y.TvProgramId).CurrentValue == program.TvProgramId
                && x.Property(y => y.SeriesNumber).CurrentValue == seriesNumber
                && x.Property(y => y.EpisodeNumber).CurrentValue == episodeNumber
            );
            if (local != null) {
                return local.Entity;
            }

            // find the *FIRST* matching item
            return TvEpisodes.FirstOrDefault(x =>
                x.TvProgramId == program.TvProgramId
                && x.SeriesNumber == seriesNumber
                && x.EpisodeNumber == episodeNumber
            );
        }
コード例 #4
0
ファイル: TvDataContext.cs プロジェクト: olliholliday/TvList
        protected TvProgramEpisode GetOrCreateTvProgramEpisodeFromListingInfo(TvProgram program, IAddTvBroadCastListingInfo info)
        {
            TvProgramEpisode episode;

            // first check if our new info has both series and episode number
            if (info.SeriesNumber.HasValue && info.EpisodeNumber.HasValue) {

                // check in the database for matching ProgramId, SeriesNumber, EpisodeNumber - that's a definitive link
                episode = FindExistingEpisodeByNumber(program, info.SeriesNumber, info.EpisodeNumber);
                if (
                    episode == null // nothing found at all
                    || episode.EpisodeTitle != info.EpisodeTitle // an in-exact match which we'll duplicate
                    || episode.EpisodeDescription != info.EpisodeDescription
                ) {

                    // create one with this info and save it
                    episode = new TvProgramEpisode {
                        TvProgram = program,
                        EpisodeTitle = info.EpisodeTitle,
                        EpisodeDescription = info.EpisodeDescription,
                        SeriesNumber = info.SeriesNumber,
                        EpisodeNumber = info.EpisodeNumber
                    };
                    TvEpisodes.Add(episode);

                }

            }
            // If the series and episode aren't both set check if the episodetitle is set
            else {

                // if it is, check for an exact match on episodetitle and episodedescription
                episode = FindExistingEpisodeByDescription(program, info.EpisodeTitle, info.EpisodeDescription);
                if (
                    episode == null // nothing found at all
                    || episode.SeriesNumber != info.SeriesNumber // an in-exact match which we'll duplicate
                    || episode.EpisodeNumber != info.EpisodeNumber // an in-exact match which we'll duplicate
                ) {

                    // create a new one and save it
                    episode = new TvProgramEpisode {
                        TvProgram = program,
                        EpisodeTitle = info.EpisodeTitle,
                        EpisodeDescription = info.EpisodeDescription,
                        SeriesNumber = info.SeriesNumber,
                        EpisodeNumber = info.EpisodeNumber
                    };
                    TvEpisodes.Add(episode);

                }

            }

            return episode;
        }
コード例 #5
0
ファイル: TvDataContext.cs プロジェクト: olliholliday/TvList
        /// <summary>
        /// Locates an existing TvEpisode by simple name match, or returns null if none found
        /// </summary>
        /// <param name="episodeTitle"></param>
        /// <returns></returns>
        protected TvProgramEpisode FindExistingEpisodeByDescription(TvProgram program, string episodeTitle, string episodeDescription)
        {
            if (program.TvProgramId == 0) {
                return null;
            }

            var local = ChangeTracker.Entries<TvProgramEpisode>().FirstOrDefault(x =>
                x.Property(y => y.TvProgramId).CurrentValue == program.TvProgramId
                && x.Property(y => y.EpisodeTitle).CurrentValue == episodeTitle
                && x.Property(y => y.EpisodeDescription).CurrentValue == episodeDescription
            );
            if (local != null) {
                return local.Entity;
            }

            // find the *FIRST* matching item
            return TvEpisodes.FirstOrDefault(x =>
                x.TvProgramId == program.TvProgramId
                && x.EpisodeTitle == episodeTitle
                && x.EpisodeDescription == episodeDescription
            );
        }