예제 #1
0
        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();

            }
        }
예제 #2
0
 // GET: Home
 public ActionResult Index()
 {
     int numberOfMovies;
     using (var db = new DBModel())
     {
         
         numberOfMovies = db.Movies.Count();
     }
     return View(numberOfMovies);
 }
예제 #3
0
        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." });
        }
예제 #4
0
 // GET: Admin
 public ActionResult Index()
 {
     DBModel db = new DBModel();
     return View(db.Movies.OrderBy(m => m.Title).ToList());
 }