Exemple #1
0
        // GET: Details
        public ActionResult Details(int id)
        {
            var svc   = new AudiobookService();
            var model = svc.GetAudiobookById(id);

            return(View(model));
        }
Exemple #2
0
        // GET: Audiobook
        public ActionResult Index()
        {
            var service = new AudiobookService();
            var model   = service.GetAudiobooks();

            return(View(model));
        }
Exemple #3
0
        private static AudiobookDetail GetAudiobookService(int id)
        {
            var service = new AudiobookService();
            var detail  = service.GetAudiobookById(id);

            return(detail);
        }
Exemple #4
0
        public ActionResult DeletePost(int id)
        {
            var service = new AudiobookService();

            service.DeleteAudiobook(id);

            TempData["SaveResult"] = "Your audiobook was deleted";

            return(RedirectToAction("Index"));
        }
Exemple #5
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));
        }
Exemple #6
0
        public ActionResult Edit(int id, AudiobookEdit audiobookToBeEdited)
        {
            if (!ModelState.IsValid)
            {
                return(View(audiobookToBeEdited));
            }

            if (audiobookToBeEdited.AudiobookId != id)
            {
                ModelState.AddModelError("", "ID does not match an existing item, please try again.");
                return(View(audiobookToBeEdited));
            }

            var service = new AudiobookService();

            if (service.UpdateAudiobook(audiobookToBeEdited))
            {
                TempData["SaveResult"] = "Your audiobook was updated.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Your audiobook could not be updated.");
            return(View(audiobookToBeEdited));
        }