Created
August 28, 2014 17:09
-
-
Save ardalis/6a624532050961000bf4 to your computer and use it in GitHub Desktop.
Tightly Coupled Controller Index
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Data; | |
using System.Data.Entity; | |
using System.Linq; | |
using System.Net; | |
using System.Web; | |
using System.Web.Mvc; | |
using MvcMovie.Models; | |
namespace MvcMovie.Controllers | |
{ | |
public class MoviesController : Controller | |
{ | |
private MovieDBContext db = new MovieDBContext(); | |
// GET: /Movies/ | |
public ActionResult Index(string movieGenre, string searchString) | |
{ | |
var GenreLst = new List<string>(); | |
var GenreQry = from d in db.Movies | |
orderby d.Genre | |
select d.Genre; | |
GenreLst.AddRange(GenreQry.Distinct()); | |
ViewBag.movieGenre = new SelectList(GenreLst); | |
var movies = from m in db.Movies | |
select m; | |
if (!String.IsNullOrEmpty(searchString)) | |
{ | |
movies = movies.Where(s => s.Title.Contains(searchString)); | |
} | |
if (!string.IsNullOrEmpty(movieGenre)) | |
{ | |
movies = movies.Where(x => x.Genre == movieGenre); | |
} | |
return View(movies); | |
} | |
// more methods | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment