Skip to content

Instantly share code, notes, and snippets.

View mugilan-ragupathi's full-sized avatar

Mugilan Ragupathi mugilan-ragupathi

View GitHub Profile
[HttpPost]
public ActionResult Delete(Movie movieToDelete)
{
if (ModelState.IsValid)
{
//Update the data in db and show the list of movies
using (var db = new MovieDBContext())
{
db.Entry(movieToDelete).State = System.Data.Entity.EntityState.Deleted;
db.SaveChanges();
@model MicroIMDBV2.Models.Movie
@{
ViewBag.Title = "Delete";
}
@using (Html.BeginForm("Delete", "Movie", FormMethod.Post, new { @class = "form-horizontal" }))
{
<h2>Delete Movie</h2>
<div class="form-group">
@Html.LabelFor(m => m.Title, new { @class = "col-md-2 control-label" })
[HttpGet]
public ActionResult Delete(int id=0)
{
using (var db = new MovieDBContext())
{
Movie movie = db.Movies.Find(id);
// Find the movie from db
if (movie == null) // There is no movie with the passed id
{
return HttpNotFound();
<td>@Html.ActionLink("Edit","Edit", new {id=@movie.Id})</td>
<td>@Html.ActionLink("Delete", "Delete", new { id = @movie.Id })</td>
[HttpPost]
public ActionResult Edit(Movie movieToUpdate)
{
if (ModelState.IsValid)
{
//Update the data in db and show the list of movies
using (var db = new MovieDBContext())
{
db.Entry(movieToUpdate).State = System.Data.Entity.EntityState.Modified;
db.SaveChanges();
@model MicroIMDBV2.Models.Movie
@{
ViewBag.Title = "Edit";
}
@using (Html.BeginForm(<strong>"Edit"</strong>, "Movie", FormMethod.Post, new { @class = "form-horizontal" }))
{
<h2>Edit Movie</h2>
<div class="form-group">
[HttpGet]
public ActionResult Edit(int id=0)
{
using (var db = new MovieDBContext())
{
Movie movie = db.Movies.Find(id);
// Find the movie from db
if(movie==null) // There is no movie with the passed id
{
return HttpNotFound();
@model IEnumerable<MicroIMDBV2.Models.Movie>
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<table class="table">
<tr>
<th>Title</th>
<th>Year of Release </th>
</tr>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>