public ActionResult Create(AudiobookCreate model) { if (!ModelState.IsValid) { return(View(model)); } var service = new AudiobookService(); if (service.CreateAudiobook(model)) { TempData["SaveResult"] = "Your audiobook was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Audiobook could not be created."); return(View(model)); }
public bool CreateAudiobook(AudiobookCreate model) { var audiobookToCreate = new Audiobook() { Title = model.Title, SeriesTitle = model.SeriesTitle, AuthorId = model.AuthorId, Isbn = model.Isbn, Rating = model.Rating, Genre = model.Genre, Language = model.Language, Publisher = model.Publisher, NarratorName = model.NarratorName, AudioFormat = model.AudioFormat, IsAbridged = model.IsAbridged }; using (var ctx = new ApplicationDbContext()) { ctx.Audiobooks.Add(audiobookToCreate); return(ctx.SaveChanges() == 1); } }