예제 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (var db = new ReviewContext())
            {
                var movieId = int.Parse(Request.QueryString["id"]);
                movieInstance = db.Movies.First(m => m.Id == movieId);

                if (IsPostBack)
                {
                    string title   = Request.Form["title"];
                    string genre   = Request.Form["genre"];
                    string imdbURL = Request.Form["imdbURL"];
                    string release = Request.Form["release"];
                    string img     = Request.Form["img"];

                    if (title != "")
                    {
                        movieInstance.Title = title;
                    }

                    if (genre != "")
                    {
                        movieInstance.Genre = genre;
                    }

                    if (imdbURL != "")
                    {
                        movieInstance.IMDB = imdbURL;
                    }

                    if (img != "")
                    {
                        movieInstance.imgURL = img;
                    }

                    if (release != "")
                    {
                        movieInstance.ReleaseDate = release;
                    }

                    db.Entry(movieInstance).State = EntityState.Modified;
                    db.SaveChanges();
                    Response.Redirect("Default.aspx");
                }
            }
        }
예제 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Request.Form.AllKeys.Contains("title"))
            if (IsPostBack)
            {
                using (var db = new ReviewContext())
                {
                    var movie = new Movie
                    {
                        Title       = Request.Form["title"],
                        Genre       = Request.Form["genre"],
                        IMDB        = Request.Form["imdbURL"],
                        imgURL      = Request.Form["img"],
                        ReleaseDate = Request.Form["release"]
                    };

                    db.Movies.Add(movie);
                    db.SaveChanges();

                    Response.Redirect("Default.aspx");
                }
            }
        }