コード例 #1
0
        //
        // GET: /StoreManager/Create

        public ActionResult Create()
        {
            var viewModel = new StoreManagerViewModel
            {
                Album = new Album(),
                Genres = storeDB.Genres.ToList(),
                Artists = storeDB.Artists.ToList()
            };

            return View(viewModel);
        }
コード例 #2
0
        public ActionResult Create(Album album)
        {
            if (ModelState.IsValid)
            {

                //Save Album
                storeDB.AddToAlbums(album);
                storeDB.SaveChanges();

                return RedirectToAction("Index");

            }

            // Invalid – redisplay with errors
            var viewModel = new StoreManagerViewModel
            {
                Album = album,
                Genres = storeDB.Genres.ToList(),
                Artists = storeDB.Artists.ToList()
            };

            return View(viewModel);
        }
コード例 #3
0
        //
        // GET: /StoreManager/Edit/5

        public ActionResult Edit(int id)
        {
            var viewModel = new StoreManagerViewModel
            {
                Album = storeDB.Albums.Single(a => a.AlbumId == id),
                Genres = storeDB.Genres.ToList(),
                Artists = storeDB.Artists.ToList()
            };

            return View(viewModel);
        }