Ejemplo n.º 1
0
        public ActionResult Create(Movie movie)
        {
            if (ModelState.IsValid)
            {
                movieDataHandler.Create(movie);
                return RedirectToAction("Index");
            }

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

            return View(movie);
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 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();
     }
 }
Ejemplo n.º 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");
            }
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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));
            }
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 16
0
 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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();
 }
Ejemplo n.º 21
0
 public void testAdd()
 {
     Movie movie = new Movie();
     _context.Movie.Add(movie);
     _context.SaveChanges();        // <= Will throw server side validation exception 
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 23
0
 public ActionResult Edit(Movie movie)
 {
     if (ModelState.IsValid)
     {
         UpdateMovie(movie);
         return RedirectToAction("Index");
     }
     return View(movie);
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 25
0
 public MovieListViewModel(IQueryable<Movie> movies)
 {
     _movies = movies;
     Title = "Movies";
     Sample = new Movie();
 }
Ejemplo n.º 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);
 }