コード例 #1
0
 public ActionResult Create(MovieSet movie)
 {
     if (ModelState.IsValid)
     {
         using (var ctx = new MoviesContext())
         {
             ctx.AddToMovieSets(movie);
             ctx.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     return View(movie);
 }
コード例 #2
0
        public ActionResult Delete(int id)
        {
            try
            {
                using(var ctx = new MoviesContext())
                {
                    var movie = ctx.MovieSets.Where(m => m.ID == id).First();
                    ctx.DeleteObject(movie);
                    ctx.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
コード例 #3
0
 //
 // GET: /Movie/Edit/5
 public ActionResult Edit(int id)
 {
     var ctx = new MoviesContext();
     var movie = ctx.MovieSets.Where(m => m.ID == id).First();
     return View(movie);
 }
コード例 #4
0
        public ActionResult MovieDetails(int id)
        {
            using (var ctx = new MoviesContext())
            {
                var movie = ctx.MovieSets
                    .Include("Reviews")
                    .Where(m => m.ID == id)
                    .FirstOrDefault();

                return View(movie);
            }
        }
コード例 #5
0
 //
 // GET: /Movie/
 public ActionResult Index(int? page, string q)
 {
     var ctx = new MoviesContext();
     var movies = ctx.MovieSets
                     .Where(m => m.Title.StartsWith(q) || q== null)
                     .OrderByDescending(m => m.ReleaseDate)
                     .AsPagination(page ?? 1, 3);
     return View(movies);
 }
コード例 #6
0
        public ActionResult Edit(int id, FormCollection collection)
        {
            var ctx = new MoviesContext();
            var movie = ctx.MovieSets.Where(m => m.ID == id).First();

            UpdateModel(movie, new string[] { "Title", "ReleaseDate.Year", "ImageUrl" }, collection.ToValueProvider());

            if (ModelState.IsValid)
            {
                ctx.SaveChanges();
                return RedirectToAction("Index");
            }

            return View();
        }