public ActionResult Create(PodcastBase podcastBase) { if ((ModelState.IsValid) && (podcastBase.dsTitulo != "")) { if (podcastBase.PodcastBaseID == 0) { db.Podcasts.Add(podcastBase); } else { db.Entry(podcastBase).State = EntityState.Modified; } db.SaveChanges(); } else { throw new FormatException("Informações inválidas"); } return(RedirectToAction("Index")); }
public void CanInsertMovieIntoDatabase() { var builder = new DbContextOptionsBuilder <PodcastContext>(); builder.UseInMemoryDatabase("CanInsertMovie"); using (var context = new PodcastContext(builder.Options)) { var movie = new Movie(); context.Movies.Add(movie); context.SaveChanges(); Debug.WriteLine($"Inserted ID: {movie.Id}"); Assert.AreNotEqual(0, movie.Id); } }
public void CanInsertHostIntoDatabase() { var builder = new DbContextOptionsBuilder <PodcastContext>(); builder.UseInMemoryDatabase("PodcastTestingDatabase"); using (var context = new PodcastContext(builder.Options)) { var host = new Host(); context.Hosts.Add(host); context.SaveChanges(); Debug.WriteLine($"Inserted ID: {host.Id}"); Assert.AreNotEqual(0, host.Id); } }
public static void Initialize(PodcastContext context) { if (!context.Authors.Any()) { context.Authors.AddRange( new Author { Name = "Disgusting men", Description = "Это еженедельный подкаст с disgustingmen.com. Мы говорим о кинематографе, музыке, светской жизни, путешествиях и видеоиграх.", Image = "http://drive.google.com/uc?export=view&id=1ya_nPmBefspSlzxTGf1pQ-3Viyby75tw" } ); context.SaveChanges(); } }