public IActionResult Create(TvChannel tvChannel) { if (ModelState.IsValid) { _context.TvChannels.Add(tvChannel); _context.SaveChanges(); return RedirectToAction("Index"); } return View(tvChannel); }
/// <summary> /// Locates or creates a TvChannel and its corresponding TvChannelListingSource /// </summary> /// <param name="import"></param> /// <param name="info"></param> /// <returns></returns> public TvChannelListingSource AddTvChannelListingSource(TvProgramBroadCastListingImport import, IAddTvChannelSourceInfo info) { // try and find a matching channel by uri var local = ChangeTracker.Entries<TvChannelListingSource>().SingleOrDefault(x => x.Property(y => y.SourceChannelUri).CurrentValue == info.Uri); if (local != null) return local.Entity; // try and find a matching channel by uri var remote = TvChannelListingSources.SingleOrDefault(x => x.SourceChannelUri == info.Uri); if (remote != null) return remote; // add a channel with that displayname var newChan = new TvChannel { ChannelName = info.DisplayName.Trim() }; TvChannels.Add(newChan); // and a link between it and the source with the info it needs for future requests var newSource = new TvChannelListingSource { SourceChannelUri = info.Uri, SourceChannelName = info.SourceName }; TvChannelListingSources.Add(newSource); return newSource; }