// GET: Movie // public ActionResult Index() // { // return View(); // } public ViewResult Index() { var db = new ImdbContext(); var movies = db.Movies; ViewData.Model = movies; return View(); }
private static void DownloadCoverImages() { Console.WriteLine("Downloading cover images"); string path = @"C:\Users\ProgramUtvikling\Documents\MovieCovers"; using (var db = new ImdbContext()) { foreach (var movie in db.Movies) { try { var req = WebRequest.Create("http://hemmelignummeroghemmeligadres.se/" + movie.MovieId + ".jpg"); var response = req.GetResponse(); string filename = Path.Combine(path, movie.MovieId + ".jpg"); using (var fs = new FileStream(filename, FileMode.Create)) { response.GetResponseStream().CopyTo(fs); } Console.Write("."); } catch (Exception) { Console.WriteLine("e"); } } } }
public ActionResult CreateImage(string format, string id) { var pixel = 0; switch (format) { case "thumb": pixel = 100; break; case "medium": pixel = 300; break; default: return HttpNotFound(); } if (format.Equals("thumb")) pixel = 100; var db = new ImdbContext(); var movie = db.Movies.Find(id); var filename = Server.MapPath("~/App_Data/covers/" + movie.MovieId + ".jpg"); new WebImage(filename) .Resize(pixel, pixel) .Write(); return new EmptyResult(); }
public static ValidationResult CheckIdLocal(string movieId) { var db = new ImdbContext(); if(db.Movies.Any(m => m.MovieId == movieId)) { return new ValidationResult("Filmen er allerede registrert (local)"); } return ValidationResult.Success; }
public ViewResult Details(int id) { var db = new ImdbContext(); var person = db.Persons.Find(id); ViewData.Model = person; return View(); }
//public string Index() //{ // return "Hei"; //} public ViewResult Details(string id) { var db = new ImdbContext(); var movie = db.Movies.Find(id); ViewData.Model = movie; return View(); }
public JsonResult checkIdRemote(string id) { var db = new MovieDAL.ImdbContext(); if (db.Movies.Any(x => x.MovieId == id)) { return Json("Movie is already registered"); } return Json(true); }
public static ValidationResult NewMovie(string movieId) { ImdbContext db = new ImdbContext(); if (db.Movies.Find(movieId) == null) { return ValidationResult.Success; } else return new ValidationResult("Filmen finnes fra før"); }
private static void Load(ImdbContext db) { Console.WriteLine("Starting to seed database..."); Console.WriteLine("Loading from Access DB"); var ds = LoadFromAccessDb(); Console.WriteLine("Writing to SQL DB"); foreach (var skuespiller in ds.skuespiller) { Console.Write("a"); var actor = new Person { Name = skuespiller.navn }; db.Persons.Add(actor); } var produsenter = ds.produsent.Select(p => p.navn); var skuespillere = ds.skuespiller.Select(p => p.navn); foreach (var navn in produsenter.Except(skuespillere)) { Console.Write("p"); var person = new Person { Name = navn }; db.Persons.Add(person); } db.SaveChanges(); Console.WriteLine(); foreach (var kategori in ds.kategori) { var genre = new Genre { Name = kategori.tekst.Trim() }; db.Genres.Add(genre); Console.WriteLine(kategori.tekst); foreach (var film in kategori.GetfilmRows()) { var movie = new Movie { MovieId = film.id, Genre = genre, Description = film.kommentar, OriginalTitle = film.orgtittel, Title = film.tittel, ProductionYear = film.innspiltaar, RunningLength = film.spilletid, Actors = new List<Person>(), Producers = new List<Person>(), Directors = new List<Person>() }; foreach (var skuespill in film.GetskuespillRows()) { Console.Write("a"); var actor = db.Persons.Single(p => p.Name == skuespill.skuespillerRow.navn); movie.Actors.Add(actor); } foreach (var produsert in film.GetprodusertRows()) { Console.Write("p"); var producer = db.Persons.Single(p => p.Name == produsert.produsentRow.navn); movie.Producers.Add(producer); } foreach (var regissert in film.GetregissertRows()) { Console.Write("d"); var director = db.Persons.Single(p => p.Name == regissert.produsentRow.navn); movie.Directors.Add(director); } db.Movies.Add(movie); Console.Write("."); } Console.WriteLine(); } Console.WriteLine("Database seeded, now saving..."); db.SaveChanges(); }
static void Main(string[] args) { Console.WriteLine("Starting import"); var sw = Stopwatch.StartNew(); Database.SetInitializer(new MigrateDatabaseToLatestVersion<ImdbContext, Configuration>()); var db = new ImdbContext(); if (!db.Persons.Any()) { Load(db); Console.WriteLine("{0} movies and {1} persons imported (duration: {2})", db.Movies.Count(), db.Persons.Count(), sw.Elapsed); } //DownloadCoverImages(); Console.WriteLine("Press ENTER..."); Console.ReadLine(); }