public ActionResult Create(Album album)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // Save Album
                    storeDB.AddToAlbums(album);
                    storeDB.SaveChanges();

                    return Redirect("Index");
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError(String.Empty, ex);
            }

            // Invalid - redisplay with errors

            var viewModel = new StoreManagerViewModel()
            {
                Album = album,
                Genres = new SelectList(storeDB.Genres.ToList(), "GenreId", "Name", album.GenreId),
                Artists = new SelectList(storeDB.Artists.ToList(), "ArtistId", "Name", album.ArtistId)
            };

            return View(viewModel);
        }
        public ActionResult Create(Album album)
        {
            try
            {
                //Save Album
                using (var tx = storeContext.Session.BeginTransaction())
                {
                    storeContext.Session.Save(album);

                    tx.Commit();
                }

                return Redirect("/");
            }
            catch
            {
                //Invalid - redisplay with errors

                var viewModel = new StoreManagerViewModel
                {
                    Album = album,
                    Genres = storeContext.Genres.ToList(),
                    Artists = storeContext.Artists.ToList()
                };

                return View(viewModel);
            }
        }
示例#3
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            var album = storeDB.Albums.Single(a => a.AlbumId == id);

            try
            {
                // Save Album

                UpdateModel(album, "Album");
                storeDB.SaveChanges();

                return RedirectToAction("Index");
            }
            catch
            {
                // Error occurred - so redisplay the form

                var viewModel = new StoreManagerViewModel()
                {
                    Album = album,
                    Genres = new SelectList(storeDB.Genres.ToList(), "GenreId", "Name", album.GenreId),
                    Artists = new SelectList(storeDB.Artists.ToList(), "ArtistId", "Name", album.ArtistId)
                };

                return View(viewModel);
            }
        }
示例#4
0
        //
        // GET: /StoreManager/Create

        public ActionResult Create()
        {
            var viewModel = new StoreManagerViewModel()
            {
                Album = new Album(),
                Genres = new SelectList(storeDB.Genres.ToList(), "GenreId", "Name"),
                Artists = new SelectList(storeDB.Artists.ToList(), "ArtistId", "Name")
            };
            
            return View(viewModel);
        } 
        // 
        // GET: /StoreManager/Create

        public ActionResult Create()
        {
            var viewModel = new StoreManagerViewModel
            {
                Album = new Album(),
                Genres = session.LuceneQuery<Genre>().ToList(),
                Artists = session.LuceneQuery<Album.AlbumArtist>("Artists").ToList()
            };

            return View(viewModel);
        }
        //
        // GET: /StoreManager/Edit/5

        public ActionResult Edit(string id)
        {
            var viewModel = new StoreManagerViewModel
            {
                Album = session.Load<Album>(id),
                Genres = session.LuceneQuery<Genre>().ToList(),
                Artists = session.LuceneQuery<Album.AlbumArtist>("Artists").ToList()
            };

            return View(viewModel);
        }
        //
        // GET: /StoreManager/Create
        public ActionResult Create()
        {
            var viewModel = new StoreManagerViewModel
            {
                Album = new Album(),
                Genres = _repo.Genres.ToList(),
                Artists = _repo.Artists.ToList()
            };

            return View(viewModel);
        }
示例#8
0
        //
        // GET: /StoreManager/Edit/5

        public ActionResult Edit(int id)
        {
            Album album = storeDB.Albums.Single(a => a.AlbumId == id);

            var viewModel = new StoreManagerViewModel()
            {
                Album = album,
                Genres = new SelectList(storeDB.Genres.ToList(), "GenreId", "Name", album.GenreId),
                Artists = new SelectList(storeDB.Artists.ToList(), "ArtistId", "Name", album.ArtistId)
            };

            return View(viewModel);
        }
示例#9
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);
        }
        public ActionResult Create(Album album)
        {
            try
            {
                //Save Album
                _repo.Add(album);

                return Redirect("/");
            }
            catch
            {
                //Invalid - redisplay with errors

                var viewModel = new StoreManagerViewModel
                {
                    Album = album,
                    Genres = _repo.Genres.ToList(),
                    Artists = _repo.Artists.ToList()
                };

                return View(viewModel);
            }
        }
        //
        // GET: /StoreManager/Edit/5
        public ActionResult Edit(int id)
        {
            var viewModel = new StoreManagerViewModel
            {
                Album = _repo.Albums.Single(a => a.AlbumId == id),
                Genres = _repo.Genres.ToList(),
                Artists = _repo.Artists.ToList()
            };

            return View(viewModel);
        }
        public ActionResult Edit(int id, FormCollection formValues)
        {
            var album = _repo.Albums.Single(a => a.AlbumId == id);

            try
            {
                //Save Album

                UpdateModel(album, "Album");

                return RedirectToAction("Index");
            }
            catch
            {
                var viewModel = new StoreManagerViewModel
                {
                    Album = album,
                    Genres = _repo.Genres.ToList(),
                    Artists = _repo.Artists.ToList()
                };

                return View(viewModel);
            }
        }
        public ActionResult Edit(int id, FormCollection formValues)
        {
            var album = storeContext.Albums.Single(a => a.AlbumId == id);

            using (var tx = storeContext.Session.BeginTransaction())
            {
                try
                {
                    //Save Album

                    UpdateModel(album, "Album");
                    storeContext.Session.Save(album);

                    tx.Commit();
                    return RedirectToAction("Index");
                }
                catch
                {
                    var viewModel = new StoreManagerViewModel
                                        {
                                            Album = album,
                                            Genres = storeContext.Genres.ToList(),
                                            Artists = storeContext.Artists.ToList()
                                        };

                    return View(viewModel);
                }
                finally
                {
                    // ensure the transaction is committed
                    if (tx != null && tx.WasCommitted == false)
                    {
                        tx.Commit();
                    }
                }
            }
        }