Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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);
            }
        }