public ActionResult Edit(int id, FormCollection formValues)
        {
            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  = storeDB.Genres.ToList(),
                    Artists = storeDB.Artists.ToList()
                };

                return(View(viewModel));
            }
        }
        public ActionResult Create(Album album)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    // Save Album
                    storeDB.Albums.Add(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));
        }
Beispiel #3
0
        public ActionResult Edit(int id, StoreManagerViewModel storeRequestor)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    Store store = db.Stores.Find(id);
                    if (TryUpdateModel(storeRequestor))
                    {
                        Manager manager = db.Managers.Find(store.Manager.ManagerId);
                        manager.NameM       = storeRequestor.NameM;
                        manager.Surname     = storeRequestor.Surname;
                        manager.PhoneNumber = storeRequestor.PhoneNumber;
                        //db.Managers.Add(manager);
                        store.Name    = storeRequestor.Name;
                        store.Manager = manager;
                        System.Diagnostics.Debug.WriteLine("eroare save changes");
                        //db.Stores.Add(store);
                        db.SaveChanges();
                    }
                    return(RedirectToAction("Index"));
                }

                return(View(storeRequestor));
            }
            catch (Exception e)
            {
                return(View(storeRequestor));
            }
        }
Beispiel #4
0
 public ActionResult New(StoreManagerViewModel storeRequest)
 {
     try
     {
         if (ModelState.IsValid)
         {
             Manager manager = new Manager
             {
                 NameM       = storeRequest.NameM,
                 Surname     = storeRequest.Surname,
                 PhoneNumber = storeRequest.PhoneNumber
             };
             db.Managers.Add(manager);
             Store store = new Store
             {
                 Name    = storeRequest.Name,
                 Manager = manager
             };
             db.Stores.Add(store);
             db.SaveChanges();
             return(RedirectToAction("Index"));
         }
         return(View(storeRequest));
     }
     catch (Exception e)
     {
         return(View(storeRequest));
     }
 }
        //
        // GET: /StoreManager/Create

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

            return View(viewModel);
        } 
        //
        // 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));
        }
Beispiel #7
0
        //
        // 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/Create

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

            return(View(viewModel));
        }
        //
        // 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));
        }
Beispiel #10
0
        //
        // 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));
        }
Beispiel #11
0
        public ActionResult Create(Guid companyId, string companyName)
        {
            var viewModel = new StoreManagerViewModel();

            viewModel.Store = new Store();

            viewModel.Companies           = companyContext.Collection();
            viewModel.SelectedCompanyId   = companyId.ToString();
            viewModel.SelectedCompanyName = companyName.ToString();

            return(View(viewModel));
        }
        //
        // 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));
        }
        //
        // GET: /StoreManager/Details/5

        public ActionResult Details(int id)
        {
            // Lay gia tri (đã lấy theo ID)
            // Truyen vao ViewModel
        
            var viewModel = new StoreManagerViewModel
            {
                Album = storeDB.Albums.Single(a=>a.AlbumId == id),
                Genres = storeDB.Genres.ToList(),
                Artists = storeDB.Artists.ToList()
            };
            
            // Xuat ra view
            return View(viewModel);
        }
Beispiel #14
0
        // -- In Edit I use ViewModel so the user can select the Company from list with all existing companies in the Db
        public ActionResult Edit(Guid Id)
        {
            Store store = storeContext.Find(Id);

            if (store == null)
            {
                return(HttpNotFound());
            }
            else
            {
                var viewModel = new StoreManagerViewModel();
                viewModel.Store     = store;
                viewModel.Companies = companyContext.Collection();
                return(View(viewModel));
            }
        }
        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(FormCollection collection)
        public ActionResult Create(Album album)
        {
            try
            {
                // TODO: Add insert logic here

                storeDB.AddToAlbums(album);
                storeDB.SaveChanges();
                //return RedirectToAction("Index");
                return RedirectToAction("/");
            }
            catch
            {
                // Invalid - ReDisplay with Errors
                var viewModel = new StoreManagerViewModel { 
                    Album = album,
                    Artists = storeDB.Artists.ToList(),
                    Genres = storeDB.Genres.ToList()
                };
                return View(viewModel);
            }
        }
Beispiel #17
0
        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));
            }
        }
Beispiel #18
0
        public ActionResult Edit(int?id)
        {
            if (id.HasValue)
            {
                Store store = db.Stores.Find(id);


                if (store == null)
                {
                    return(HttpNotFound("Couldn't find the store with id " + id.ToString() + "!"));
                }

                StoreManagerViewModel storeM = new StoreManagerViewModel
                {
                    Name        = store.Name,
                    NameM       = store.Manager.NameM,
                    Surname     = store.Manager.Surname,
                    PhoneNumber = store.Manager.PhoneNumber,
                };
                System.Diagnostics.Debug.Write("am ajuns");
                return(View(storeM));
            }
            return(HttpNotFound("Couldn't find the store with id " + id.ToString() + "!"));
        }
Beispiel #19
0
        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 collection)
        {
            // Lấy thông tin đối tượng cần cập nhật thông qua ID
            var album = storeDB.Albums.Single(a => a.AlbumId == id);

            try
            {
                // TODO: Add update logic here
                // Cập nhật thông tin mới
                UpdateModel(album, "Album"); // cap nhật doi tuong Album tu Model
                storeDB.SaveChanges();

                // Lưu xong trả về trang Index
                return RedirectToAction("Index");
                
            }
            catch
            {
                // Trả lại trang View nếu không cập nhật được
                // album.Title = "LOI CAP NHAT - " + album.Title;
                var viewModel = new StoreManagerViewModel
                {
                    Album = album,
                    Artists = storeDB.Artists.ToList(),
                    Genres = storeDB.Genres.ToList()
                };

                return View(viewModel);
            }
        }
        //
        // GET: /StoreManager/Edit/5
 
        public ActionResult Edit(int id)
        {
            // Lay gia tri và truyền vào biến viewModel
            var viewModel = new StoreManagerViewModel
            {
                Album = storeDB.Albums.Single(a => a.AlbumId == id),
                Artists = storeDB.Artists.ToList(),
                Genres = storeDB.Genres.ToList()
            };

            // viewModel.Album.Title = "TEST " + viewModel.Album.Title;

            // Trả kết quả ra cho View
            return View(viewModel);
        }
Beispiel #22
0
        public ActionResult New()
        {
            StoreManagerViewModel store = new StoreManagerViewModel();

            return(View(store));
        }