
Originally Posted by
traq
I've never seen your code, so I don't have any more specific advice
( hint, hint ... )
Sorry, i have much work to do (projects)
So the code is below 
Code:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CarReviews.Models;
namespace CarReviews.Controllers
{
[Authorize]
public class CarController : Controller
{
private RidesEntities db = new RidesEntities();
//
// GET: /Default1/
[Authorize(Roles = "Admin")]
public ViewResult Index()
{
var cars = db.Cars.Include(c => c.Pricing);
return View(cars.ToList());
}
//
// GET: /Default1/Details/5
public ViewResult Details(int id)
{
Car car = db.Cars.Find(id);
return View(car);
}
//
// GET: /Default1/Create
// [Authorize(Users="Bob")]
[Authorize(Roles = "admin")]
[Authorize(Roles = "user")]
public ActionResult Create()
{
ViewBag.price_id = new SelectList(db.Pricings, "price_id", "insurance_group");
return View();
}
//
// POST: /Default1/Create
[HttpPost]
public ActionResult Create(Car car)
{
if (ModelState.IsValid)
{
db.Cars.Add(car);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.price_id = new SelectList(db.Pricings, "price_id", "insurance_group", car.price_id);
return View(car);
}
//
// GET: /Default1/Edit/5
public ActionResult Edit(int id)
{
Car car = db.Cars.Find(id);
ViewBag.price_id = new SelectList(db.Pricings, "price_id", "insurance_group", car.price_id);
return View(car);
}
//
// POST: /Default1/Edit/5
[HttpPost]
public ActionResult Edit(Car car)
{
if (ModelState.IsValid)
{
db.Entry(car).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.price_id = new SelectList(db.Pricings, "price_id", "insurance_group", car.price_id);
return View(car);
}
//
// GET: /Default1/Delete/5
public ActionResult Delete(int id)
{
Car car = db.Cars.Find(id);
return View(car);
}
//
// POST: /Default1/Delete/5
[HttpPost, ActionName("Delete")]
public ActionResult DeleteConfirmed(int id)
{
Car car = db.Cars.Find(id);
db.Cars.Remove(car);
db.SaveChanges();
return RedirectToAction("Index");
}
protected override void Dispose(bool disposing)
{
db.Dispose();
base.Dispose(disposing);
}
}
}
Bookmarks