public ActionResult Create(Movie movie)
        {
            if (ModelState.IsValid)
            {
                movieDataHandler.Create(movie);
                return RedirectToAction("Index");
            }

            return View(movie);
        }
예제 #2
0
 public ActionResult Edit(Movie movie)
 {
     if (ModelState.IsValid)
     {
         db.Entry(movie).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(movie);
 }
예제 #3
0
 public IActionResult Create(Movie movie)
 {
     if (ModelState.IsValid)
     {
         _context.Movie.Add(movie);
         _context.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(movie);
 }
예제 #4
0
        public ActionResult Create(Movie movie)
        {
            if (ModelState.IsValid) {
                var collection = GetMoviesCollection();
                collection.Insert(movie);
                return RedirectToAction("Index");
            }

            return View(movie);
        }
예제 #5
0
 public ActionResult Create(Movie movie)
 {
     if (ModelState.IsValid)
     {
         db.Movies.Add(movie);
         db.SaveChanges();
         return RedirectToAction("Index", "Movies");
     }
     return View(movie);
 }
 public ActionResult Create(Movie newMovie)
 {
     if (ModelState.IsValid) {
         // TODO: Implement view model to add the actors. The following was tested to work OK:
         //Actor actor = _actorRepository.FindById(1);
         //newMovie.Actors = new List<Actor>();
         //newMovie.Actors.Add(actor);
         _repository.Save(newMovie);
         return RedirectToAction("Index");
     } else {
         return View(newMovie);
     }
 }
예제 #7
0
        public ActionResult Delete(Movie movie)
        {
            try
            {
                // TODO: Add delete logic here
                DeleteMovie(movie.ID);
                return JavaScript("window.top.location.href ='Movies';");

            }
            catch
            {
                return View();
            }
        }
예제 #8
0
 public ActionResult Create(FormCollection collection)
 {
     try
     {
         // TODO: Add insert logic here
         Movie mv=new Movie();
         mv.Title = collection["Title"].ToString();
         mv.ReleaseDate = Convert.ToDateTime(collection["ReleaseDate"].ToString());
         mv.Genre = collection["Genre"].ToString();
         mv.Price = Convert.ToDecimal(collection["Price"].ToString());
         InsertMovie(mv);
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
예제 #9
0
        public ActionResult Create(Movie movie)
        {
            if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated)
            {
                if (ModelState.IsValid)
                {
                    movie.Useradd = System.Web.HttpContext.Current.User.Identity.Name;
                    db.Movies.Add(movie);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }

                return View(movie);
            }
            else
            {
                return RedirectToAction("LogOn", "Account");
            }
        }
예제 #10
0
 //
 // GET: /Movies/Delete/5
 public ActionResult Delete(int id)
 {
     List<MvcMovie.Models.Movie> lstMoview = new List<Movie>();
     for (int i = 0; i < 5; i++)
     {
         Movie mv = new Movie();
         mv.ID = i;
         mv.Title = "film " + i;
         mv.Genre = "film " + i;
         mv.Price = i;
         lstMoview.Add(mv);
     }
     IEnumerable<Movie> obj = from i in lstMoview where i.ID == id select i;
     if (obj.Count() > 0)
     {
         Movie movie = (from i in lstMoview where i.ID == id select i).First();
         return Content(Boolean.TrueString);
     }
     else
     {
         return Content(Boolean.FalseString);
     }
 }
예제 #11
0
 private int UpdateMovie(Movie mv)
 {
     int res = 0;
     Database db = DatabaseFactory.CreateDatabase("cnnString");
     DbCommand dbCommand = db.GetSqlStringCommand("Update Movies set Title=@Title, ReleaseDate=@ReleaseDate,Genre=@Genre,Price=@Price where ID=@ID");
     db.AddInParameter(dbCommand, "Title", DbType.String, mv.Title);
     db.AddInParameter(dbCommand, "ReleaseDate", DbType.Date, mv.ReleaseDate);
     db.AddInParameter(dbCommand, "Genre", DbType.String, mv.Genre);
     db.AddInParameter(dbCommand, "Price", DbType.Decimal, mv.Price);
     db.AddInParameter(dbCommand, "ID", DbType.Int32, mv.ID);
     res=db.ExecuteNonQuery(dbCommand);
     return res;
 }
예제 #12
0
 private int InsertMovie(Movie mv)
 {
     int res = 0;
     Database db = DatabaseFactory.CreateDatabase("cnnString");
     DbCommand dbCommand = db.GetSqlStringCommand("Insert Movies values(@Title,@ReleaseDate,@Genre,@Price)");
     db.AddInParameter(dbCommand, "Title", DbType.String, mv.Title);
     db.AddInParameter(dbCommand, "ReleaseDate", DbType.Date, mv.ReleaseDate);
     db.AddInParameter(dbCommand, "Genre", DbType.String, mv.Genre);
     db.AddInParameter(dbCommand, "Price", DbType.Decimal, mv.Price);
     res = db.ExecuteNonQuery(dbCommand);
     return res;
 }
예제 #13
0
        public ActionResult SearchIndex(string movieGenre, string searchString)
        {
            List<MvcMovie.Models.Movie> lstMoview = new List<Movie>();
            for (int i = 0; i < 5; i++)
            {
                Movie mv = new Movie();
                mv.ID = i;
                mv.Title = "film " + i;
                mv.Genre = "genre " + i;
                lstMoview.Add(mv);
            }
            var GenreLst = new List<string>();

            var GenreQry = from d in lstMoview
                           orderby d.Genre
                           select d.Genre;
            GenreLst.AddRange(GenreQry.Distinct());
            ViewBag.movieGenre = new SelectList(GenreLst);

            IEnumerable<Movie> movies = null;

            if (!String.IsNullOrEmpty(searchString))
            {
                movies = lstMoview.Where(s => s.Title.Contains(searchString));
            }
            if (string.IsNullOrEmpty(movieGenre))
                return View(movies);
            else
            {
                return View(movies.Where(x => x.Genre == movieGenre));
            }
        }
예제 #14
0
        public Movie GetMoviesByID(int id)
        {
            List<Movie> lstMoview = new List<Movie>();

            Database db = DatabaseFactory.CreateDatabase("cnnString");
            DbCommand dbCommand = db.GetSqlStringCommand("select * from Movies where ID=" + id);
            IDataReader dr = db.ExecuteReader(dbCommand);
            while (dr.Read())
            {
                Movie mv = new Movie();
                mv.ID = Convert.ToInt32(dr["ID"]);
                mv.Title = dr["Title"].ToString();
                mv.ReleaseDate = Convert.ToDateTime(dr["ReleaseDate"].ToString());
                mv.Genre = dr["Genre"].ToString();
                mv.Price = Convert.ToDecimal(dr["Price"].ToString());
                lstMoview.Add(mv);
            }
            if (lstMoview.Count > 0)
                return lstMoview.First();
            else
            {
                return null;
            }
        }
예제 #15
0
        // GET: Movies/Edit/5
        // This method is called from a button click within the browser
        public IActionResult Edit(int? id)
        {
            Debug.WriteLine("\n  AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n    id = " + id);
            fakeData1();

            if (id == null)
            {
                return HttpNotFound();
            }

            //Movie movie = _context.Movie.Single(m => m.ID == id);
            Movie movie = new Movie();
            int count = movieList.Count;

            for(int i=0; i<count; i++)
            {
                if(id.Equals(movieList.ElementAt(i).ID))
                {
                    movie = movieList.ElementAt(i);
                    break;
                }
            }
                       
            if (movie == null)
            {
                return HttpNotFound();
            }
            return View(movie);
        }
 public ActionResult Edit(Movie movie)
 {
     if (ModelState.IsValid)
     {
         var collection = GetMoviesCollectionForEdit();
         collection.Save(movie);
         return RedirectToAction("Index");
     }
     return View(movie);
 }
        public ActionResult Edit(Movie model)
        {
            try {
                Movie movie = _repository.FindById(model.ID);
                UpdateModel(movie);
                _repository.Save(movie);
                return RedirectToAction("Details", new { id = model.ID });
            } catch (Exception) {
                ModelState.AddModelError("", "Edit Failure, see inner exception");
            }

            return View(model);
        }
예제 #18
0
 public ActionResult Edit(Movie movie)
 {
     if (ModelState.IsValid)
     {
         movie.Useradd = System.Web.HttpContext.Current.User.Identity.Name;
         db.Entry(movie).State = EntityState.Modified;
         db.SaveChanges();
         return RedirectToAction("Index","Movies");
     }
     return View(movie);
 }
예제 #19
0
 private void testAdd()
 {
     Movie movie = new Movie();
     movie.Title = "Gone with the Wind";
     _context.Movie.Add(movie);
     _context.SaveChanges();        // <= Will throw server side validation exception 
 }
 public void Save(Movie movie)
 {
     throw new NotImplementedException();
 }
예제 #21
0
 public void testAdd()
 {
     Movie movie = new Movie();
     _context.Movie.Add(movie);
     _context.SaveChanges();        // <= Will throw server side validation exception 
 }
예제 #22
0
 public static void CreateImageFrom(Movie movie)
 {
     Bitmap img = DownloadImageFrom(movie.ImageLink);
     string imgPath = Path.Combine(_currentImagePath, "movie" + movie.Id + ".jpg");
     SaveImage(img, imgPath);
 }
예제 #23
0
 public ActionResult Edit(Movie movie)
 {
     if (ModelState.IsValid)
     {
         UpdateMovie(movie);
         return RedirectToAction("Index");
     }
     return View(movie);
 }
예제 #24
0
        //
        // GET: /Movies/
        public List<MvcMovie.Models.Movie> GetAllMovies()
        {
            List<Movie> lstMoview = new List<Movie>();

            Database db = DatabaseFactory.CreateDatabase("cnnString");
            DbCommand dbCommand = db.GetSqlStringCommand("select * from Movies");
            IDataReader dr = db.ExecuteReader(dbCommand);
            while (dr.Read())
            {
                Movie mv = new Movie();
                mv.ID = Convert.ToInt32(dr["ID"]);
                mv.Title = dr["Title"].ToString();
                mv.ReleaseDate = Convert.ToDateTime(dr["ReleaseDate"].ToString());
                mv.Genre = dr["Genre"].ToString();
                mv.Price = Convert.ToDecimal(dr["Price"].ToString());
                lstMoview.Add(mv);
            }
            return lstMoview;
        }
예제 #25
0
 public MovieListViewModel(IQueryable<Movie> movies)
 {
     _movies = movies;
     Title = "Movies";
     Sample = new Movie();
 }
예제 #26
0
 public ActionResult Edit(Movie movie)
 {
     if (ModelState.IsValid)
     {
         var collection = GetMoviesCollectionForEdit();
         try
         {
             collection.Save(movie);
             return RedirectToAction("Index");
         }
         catch
         {
             serverSettings = null;
             throw;
         }
     }
     return View(movie);
 }