Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
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 ViewResult Index()
{
return View(db.Movies.ToList());
}
 
//
// GET: /Movies/Details/5
 
public ViewResult Details(int id)
{
Movie movie = db.Movies.Find(id);
return View(movie);
}
 
//
// GET: /Movies/Create
 
public ActionResult Create()
{
return View();
}
 
//
// POST: /Movies/Create
 
[HttpPost]
public ActionResult Create(Movie movie)
{
if (ModelState.IsValid)
{
db.Movies.Add(movie);
db.SaveChanges();
return RedirectToAction("Index");
}
 
return View(movie);
}

//
// GET: /Movies/Edit/5

public ActionResult Edit(int id=0)
{
Movie movie = db.Movies.Find(id);
if (movie==null)
{
return HttpNotFound();
}
return View(movie);
}
 
//
// POST: /Movies/Edit/5
 
[HttpPost]
public ActionResult Edit(Movie movie)
{
if (ModelState.IsValid)
{
db.Entry(movie).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
return View(movie);
}
 
//
// GET: /Movies/Delete/5

public ActionResult Delete(int id)
{
Movie movie = db.Movies.Find(id);
return View(movie);
}
 
//
// POST: /Movies/Delete/5
 
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{
Movie movie = db.Movies.Find(id);
db.Movies.Remove(movie);
db.SaveChanges();
return RedirectToAction("Index");
}
 
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
 

// public ActionResult SearchIndex(string searchString)
// {
// var movies = from m in db.Movies select m;


// if(!String.IsNullOrEmpty(searchString))
// {
// movies = movies.Where(s => s.Title.Contains(searchString));
// }
 
// return View(movies);
// }
 
//[HttpPost]
// public string SearchIndex(FormCollection fc,string searchString)
//{
// return "

From [HttpPost]SearchIndex: "+searchString+"

";
//}
 

public ActionResult SearchIndex(string movieGenre,string searchString)
{
var GenreLst = new List();
var GenryQuery = from d in db.Movies
orderby d.Genre
select d.Genre;
GenreLst.AddRange(GenryQuery.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))
{
return View(movies);
}
 
else
{
return View(movies.Where(x => x.Genre == movieGenre));
}
}
}
}
Posted 30-Mar-13 19:35pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

This is not a question: it is a code dump.
Please stop posting these, or your account will be flagged as abusive and deleted.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

This isn't a question, this is a code dump. If you want to share what you've created, then post an article.
 
Code Project Article FAQ[^]
A Guide To Writing Articles For Code Project[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 587
1 Sergey Alexandrovich Kryukov 544
2 Maciej Los 325
3 DamithSL 223
4 Mathew Soji 195
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,712
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 31 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100