public static Movie GetRandomMovie() { using (var db = new DBModel()) { //Smart sätt att få en random, minns detta. return db.Database.SqlQuery<Movie>("SELECT TOP 1 * FROM dbo.Movies ORDER BY NEWID()").FirstOrDefault(); } }
// GET: Home public ActionResult Index() { int numberOfMovies; using (var db = new DBModel()) { numberOfMovies = db.Movies.Count(); } return View(numberOfMovies); }
public ActionResult AddMovie(Movie movie, string imdbId) { movie.Id = imdbId; movie.imdbRating = movie.imdbRating / 10; //Ful lösning using (var db = new DBModel()) { if (db.Movies.Any(m => m.Id == movie.Id)) { return Json(new { success = false, message = movie.Title + " is already in the database." }); } db.Movies.Add(movie); db.SaveChanges(); } return Json(new { success = true, message = movie.Title + " was added to the database." }); }
// GET: Admin public ActionResult Index() { DBModel db = new DBModel(); return View(db.Movies.OrderBy(m => m.Title).ToList()); }