Skip to content

Instantly share code, notes, and snippets.

@ardalis
Created August 28, 2014 17:09
Show Gist options
  • Save ardalis/6a624532050961000bf4 to your computer and use it in GitHub Desktop.
Save ardalis/6a624532050961000bf4 to your computer and use it in GitHub Desktop.
Tightly Coupled Controller Index
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