Exemplo n.º 1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     using (var db = new ReviewContext())
     {
         Movies = db.Movies.ToList();  // critical
         if (IsPostBack)
         {
             var movie = new Movie
             {
                 Title    = Request.Form["title"],
                 Genre    = Request.Form["genre"],
                 IMDBlink = Request.Form["imdburl"],
                 Release  = Convert.ToDateTime(Request.Form["release"]),
             };
             db.Movies.Add(movie);
             db.SaveChanges();
             Response.Redirect("Default.aspx");
         }
     }
 }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var movieId = int.Parse(Request.QueryString["id"]);

            using (var db = new ReviewContext())
            {
                movieInstance = db.Movies.First(m => m.Id == movieId);
                if (IsPostBack)
                {
                    {
                        movieInstance.Title    = Request.Form["title"];
                        movieInstance.Genre    = Request.Form["genre"];
                        movieInstance.IMDBlink = Request.Form["imdburl"];
                        movieInstance.Release  = Convert.ToDateTime(Request.Form["release"]);
                    };
                    db.Entry(movieInstance).State = EntityState.Modified;
                    db.SaveChanges();
                    Response.Redirect("Default.aspx");
                }
            }
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var movieId = int.Parse(Request.QueryString["id"]);

            using (var db = new ReviewContext())
            {
                movieInstance = db.Movies.First(m => m.Id == movieId);
                if (IsPostBack)
                {
                    var review = new Review
                    {
                        Name       = Request.Form["name"],
                        Title      = movieInstance,
                        Rating     = int.Parse(Request.Form["rating"]),
                        Age        = int.Parse(Request.Form["age"]),
                        Gender     = Request.Form["gender"],
                        Occupation = Request.Form["occupation"],
                    };
                    db.Reviews.Add(review);
                    db.SaveChanges();
                    Response.Redirect("Default.aspx");
                }
            }
        }