예제 #1
0
        public ActionResult Create([Bind(Include = "PeliculasID,Title,Director,Duration,Classification")] Peliculas peliculas)
        {
            if (ModelState.IsValid)
            {
                db.Movies.Add(peliculas);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(peliculas));
        }
예제 #2
0
        public IActionResult Create(Movie movie)
        {
            if (ModelState.IsValid)
            {
                _db.Movies.Add(movie);
                _db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            return(View());
        }
예제 #3
0
 // POST api/movies
 public Movie Post(Movie movie)
 {
     using (var db = new MoviesDB())
     {
         db.Movies.Add(movie);
         db.SaveChanges();
     }
     return(movie);
 }
예제 #4
0
        public ActionResult Add(Movies movie)
        {
            if (movie.MovieID != null)
            {
                movie = (Movies)Session["m"];
                string movieID = movie.MovieID;

                db.Movie.Add(movie);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception)
                {
                    ViewBag.ErrorMessage = "This film is already in the database.";
                    ViewBag.movie        = db.Movie;
                    return(View("Favorites"));
                }
            }
            return(RedirectToAction("Favorites"));
        }
예제 #5
0
        // Configure is called after ConfigureServices is called.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerfactory)
        {
            // Configure the HTTP request pipeline.
            // Add the console logger.
            loggerfactory.AddConsole();

            // Add the following to the request pipeline only in development environment.
            if (string.Equals(env.EnvironmentName, "Development", StringComparison.OrdinalIgnoreCase))
            {
                app.UseBrowserLink();
                app.UseErrorPage(ErrorPageOptions.ShowAll);
                app.UseDatabaseErrorPage(DatabaseErrorPageOptions.ShowAll);
            }
            else
            {
                // Add Error handling middleware which catches all application specific errors and
                // send the request to the following path or controller action.
                app.UseErrorHandler("/Home/Error");
            }

            // Add static files to the request pipeline.
            app.UseStaticFiles();

            // Add cookie-based authentication to the request pipeline.
            app.UseIdentity();

            // Add MVC to the request pipeline.
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller}/{action}/{id?}",
                    defaults: new { controller = "Movies", action = "Index" });

                // Uncomment the following line to add a route for porting Web API 2 controllers.
                // routes.MapWebApiRoute("DefaultApi", "api/{controller}/{id?}");
            });

            // Seed database
            var db = new MoviesDB();

            db.Database.EnsureCreated();
            if (db.Movies.Count() == 0)
            {
                db.Movies.Add(new Movie {
                    Title = "Memento", Director = "Nolan"
                });
                db.SaveChanges();
            }
        }
예제 #6
0
        // POST api/movies
        public Movie Post
            (string title, string genre = null)
        {
            var movie = new Movie
            {
                Title = title,
                Genre = genre,
            };

            using (var db = new MoviesDB())
            {
                db.Movies.Add(movie);
                db.SaveChanges();
            }
            return(movie);
        }
예제 #7
0
 public ActionResult Insert(Peliculas pelicula)
 {
     db.Movies.Add(pelicula);
     db.SaveChanges();
     return(RedirectToRoute("Index"));
 }