Exemplo n.º 1
0
 //
 // GET: /Movie/Edit/5
 public ActionResult Edit(int id)
 {
     using (var ctx = new MoviesContext())
     {
         var movie = ctx.MovieSet.Where(m => m.ID == id).First();
         return View(movie);
     }
 }
Exemplo n.º 2
0
 public ActionResult Delete(int id)
 {
     using (var ctx = new MoviesContext())
     {
         var movie = ctx.MovieSet.Where(m => m.ID == id).First();
         ctx.DeleteObject(movie);
         ctx.SaveChanges();
     }
     return RedirectToAction("Index");
 }
Exemplo n.º 3
0
        //
        // GET: /Movie/Details/5
        public ActionResult Details(int id)
        {
            using (var ctx = new MoviesContext())
            {
                var movie = ctx.MovieSet
                               .Include("Reviews")
                               .Where(m => m.ID == id)
                               .First();

                return View(movie);
            }
        }
Exemplo n.º 4
0
 public ActionResult Edit(int id, FormCollection collection)
 {
     using (var ctx = new MoviesContext())
     {
         var movie = ctx.MovieSet.Where(m => m.ID == id).First();
         TryUpdateModel(movie, new string[] { "Title", "ReleaseDate" });
         if (ModelState.IsValid)
         {
             ctx.SaveChanges();
             return RedirectToAction("Index");
         }
         return View(movie);
     }
 }
Exemplo n.º 5
0
 public ActionResult Create([Bind(Exclude="ID")] 
                            Movie movie)
 {
     if (ModelState.IsValid)
     {
         using (var ctx = new MoviesContext())
         {
             ctx.AddToMovieSet(movie);
             ctx.SaveChanges();
             return RedirectToAction("Index");
         }
     }
     return View();
 }
Exemplo n.º 6
0
 //
 // GET: /Movie/
 public ActionResult Index(string q)
 {
     using (var ctx = new MoviesContext())
     {
         var movies = ctx.MovieSet
                         .Where(m => m.Title.StartsWith(q) || q == null)
                         .OrderByDescending(m => m.Reviews.Average(r => r.Rating))
                         .Take(10)
                         .Select(m => new MovieSummary
                             {
                                 ID = m.ID,
                                 AverageRating = m.Reviews.Average(r => r.Rating),
                                 ReleaseDate = m.ReleaseDate,
                                 Title = m.Title
                             })
                         .ToList();
         return View(movies);
     }
 }