static void Main() { //set database Database.SetInitializer(new MigrateDatabaseToLatestVersion<MoviesEntities, Configuration>()); var context = new MoviesEntities(); var moviesCount = context.Movies.Count(); }
public List <Actor> GetActors(Decimal?actorId = 0) { using (MoviesEntities db = new MoviesEntities()) { var actorList = db.tblActors.Include("tblGender").Select(q => new Actor { _Id = q.ActorId, _Name = q.ActorName, _DateOfBirth = q.DateOfBirth, _Bio = q.Bio, _Image = new Image() { ImageID = q.ImageId, ImagePath = q.tblImage.ImagePath, Title = q.tblImage.ImageTitle, }, _Gender = new Gender() { _Name = q.tblGender.GenderName, _Id = q.tblGender.GenderId, } }).ToList(); if (actorId != 0) { actorList = actorList.Where(q => q._Id == actorId).ToList(); } return(actorList); } }
public bool Create(Movie movie) { ImageManager imageManager = new ImageManager(); decimal imageId = imageManager.SaveImage(movie._Image.ImagePath, movie._Image.Title); try { if (imageId != 0) { using (MoviesEntities db = new MoviesEntities()) { tblMovy tMovie = new tblMovy(); UpdateMovieEntity(ref tMovie, movie); tMovie.CreatedDateTime = DateTime.Now; tMovie.ImageId = imageId; db.tblMovies.Add(tMovie); db.SaveChanges(); MapMovieAndActors(tMovie.MovieId, movie._SelectedActors, db); } return(true); } else { return(false); } } catch (Exception ex) { return(false); } }
/// <summary> /// Gets the password of a certain user /// </summary> public static string GetPasswordForUser(string username) { using (MoviesEntities db = new MoviesEntities()) { return(db.Users.FirstOrDefault(u => u.Username.Equals(username, StringComparison.Ordinal)).Password); } }
[HttpGet] //4. public Movy RandomMovieCategory(string genre) { MoviesEntities ORM = new MoviesEntities(); Random r = new Random(); List <Movy> MovieList = ORM.Movies.ToList(); return(ORM.Movies.[r.Next(0, MovieList.Count)]);
public List <Movy> GetAllMovies() { MoviesEntities db = new MoviesEntities(); List <Movy> movies = db.Movies.ToList(); return(movies); }
/// <summary> /// Verifies that a user with the matching username/password exists in the database /// </summary> public static bool Login(string username, string password) { using (MoviesEntities entities = new MoviesEntities()) { return(entities.Users.Any(u => u.Username.Equals(username, StringComparison.OrdinalIgnoreCase) && u.Password == password)); } }
/// <summary> /// Verifies that a user with the matching username exists in the database /// </summary> public static bool FindUser(string username) { using (MoviesEntities entities = new MoviesEntities()) { return(entities.Users.Any(u => u.Username.Equals(username, StringComparison.OrdinalIgnoreCase))); } }
public List <string> GetListOfCategories() { MoviesEntities db = new MoviesEntities(); string category = (from c in db.Movies where c.Id == 1 select c.Category).Single(); List <string> categories = new List <string>(); categories.Add(category); for (int i = 1; i < db.Movies.Count(); i++) { string picked = (from c in db.Movies where c.Id == i select c.Category).Single(); for (int x = 0; x < categories.Count; x++) { if (!categories.Contains(picked)) { categories.Add(picked); } else { continue; } } } return(categories); }
public List <MovieList> GetRandomMovies(int id) { int l = 0; Random rnd = new Random(); List <MovieList> RandomMovies = new List <MovieList>(); while (l < id) { MoviesEntities db = new MoviesEntities(); int ran = rnd.Next(1, 15); MovieList Movie = (from p in db.MovieLists where p.ID == (ran) select p).Single(); if (RandomMovies.Contains(Movie)) { l--; } else { RandomMovies.Add(Movie); l++; } } return(RandomMovies); }
private static void MoviesAndRatings() { Console.WriteLine(); using (MoviesEntities ctx = new MoviesEntities()) { var movies = from m in ctx.Movies join g in ctx.Genres on m.GenreID equals g.GenreID select new {Rating = m.Rating, Title = m.Title, mGenre = g.TypeOfGenre, Length = m.LengthInMinutes, Desc = m.Description, Release = m.ReleaseDate, Dir = m.Director}; foreach (var m in movies) { Console.WriteLine("{0}", m.Title); Console.WriteLine(new String('-', 30)); Console.WriteLine("Relased:{0} Director:{1} Genre:{2} Rating:{3} Length:{4} min", m.Release, m.Dir, m.mGenre, m.Rating, m.Length); Console.WriteLine(); Console.WriteLine("Enter 1 to read a description or any key to continue."); string input = Console.ReadLine(); if (input == "1") Console.WriteLine("{0}", m.Desc); Console.WriteLine(); Console.WriteLine("Enter 0 to return to Menu or press enter to see next movie."); input = Console.ReadLine(); if (input == "0") return; //Console.ReadKey(); } } }
public string DeleteMovie(string movieId) { if (!String.IsNullOrEmpty(movieId)) { try { int movieIds = Int32.Parse(movieId); using (MoviesEntities entity = new MoviesEntities()) { var mv = entity.Movies.Find(movieIds); entity.Movies.Remove(mv); entity.SaveChanges(); return("Selected movie record deleted successfully"); } } catch (Exception) { return("Movie details not found"); } } else { return("Invalid operation"); } }
public bool Create(Actor actor) { ImageManager imageManager = new ImageManager(); decimal imageId = imageManager.SaveImage(actor._Image.ImagePath, actor._Image.Title); try { if (imageId != 0) { using (MoviesEntities db = new MoviesEntities()) { tblActor tActor = new tblActor(); UpdateActorEntity(ref tActor, actor); tActor.CreatedDateTime = DateTime.Now; tActor.ImageId = imageId; db.tblActors.Add(tActor); db.SaveChanges(); } return(true); } else { return(false); } } catch (Exception ex) { return(false); } }
public List <Movie> GetMovies(Decimal?movieId = 0) { using (MoviesEntities db = new MoviesEntities()) { var movieList = db.tblMovies.Include("tblActorMovies").Select(q => new { Movie1 = new Movie { _Id = q.MovieId, _Name = q.MovieName, _YearOfRelease = q.YearOfRelease, _Plot = q.Plot, _Image = new Image() { ImageID = q.ImageId, ImagePath = q.tblImage.ImagePath, Title = q.tblImage.ImageTitle, }, _ProducerName = q.tblProducer.ProducerName, _SelectedProducer = q.tblProducer.ProducerId, }, _Actor = q.tblActorMovies.Select(r => new { r.ActorId, r.tblActor.ActorName }) }).AsEnumerable().Select(p => { p.Movie1._Actors = p._Actor.ToDictionary(r => r.ActorId, r => r.ActorName); return(p.Movie1); }); if (movieId != 0) { movieList = movieList.Where(q => q._Id == movieId).ToList(); } return(movieList.ToList()); } }
public JsonResult GetAllMovies() { using (MoviesEntities entity = new MoviesEntities()) { var movieList = entity.Movies.ToList(); return(Json(movieList, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// This method resets a user's password in the database /// </summary> /// <param name="password"></param> /// <param name="userId"></param> private void ResetUserPassword(string password, int userId) { using (MoviesEntities db = new MoviesEntities()) { db.Users.FirstOrDefault(u => u.Id.Equals(userId)).Password = password; db.SaveChanges(); } }
[HttpGet] //3. public Movy RandomMovie() { MoviesEntities ORM = new MoviesEntities(); Random r = new Random(); List <Movy> MovieList = ORM.Movies.ToList(); return(MovieList[r.Next(0, MovieList.Count)]); }
public List <MovieList> GetMovies() { MoviesEntities db = new MoviesEntities(); List <MovieList> Movies = db.MovieLists.ToList(); return(Movies); }
public static void Main() { moviesContext = new MoviesEntities(); ExportAdultMovies(); ExportRatedMovieByUser("jmeyery"); ExportTopTenFavouriteFilms(); }
// GET: Movie public ActionResult Index() { using (MoviesEntities entities = new MoviesEntities()) { var list = entities.Movies.ToList(); return(View(list)); } }
public Movy GetRandomMovie() { MoviesEntities ORM = new MoviesEntities(); List <Movy> movieLst = ORM.Movies.ToList(); return(movieLst[randNum.Next(movieLst.Count)]); }
public ActionResult Details(string id) { using (MoviesEntities entities = new MoviesEntities()) { int val = Int32.Parse(id); var user = entities.Actors.FirstOrDefault(x => x.Id == val); return(View(user)); } }
public string[] GetMovieCategories() { MoviesEntities ORM = new MoviesEntities(); string[] categories = (from m in ORM.Movies select m.Category).Distinct().OrderBy(Category => Category).ToArray(); return(categories); }
public List <Movy> GetCategoryMovies(string category) { MoviesEntities db = new MoviesEntities(); List <Movy> movies = (from c in db.Movies where c.Category == category select c).ToList(); return(movies); }
public List <Movy> GetKeywordTitle(string keyword) { MoviesEntities db = new MoviesEntities(); List <Movy> movies = (from c in db.Movies where c.Title.Contains(keyword) select c).ToList(); return(movies); }
public void UpdateProducer(Producer producer) { using (MoviesEntities db = new MoviesEntities()) { tblProducer tProducer = db.tblProducers.Where(q => q.ProducerId == producer._Id).FirstOrDefault(); UpdateEntity(ref tProducer, producer); db.SaveChanges(); } }
static void Main() { var moviesContext = new MoviesEntities(); Console.WriteLine("Countries: {0}", moviesContext.Countries.Count()); Console.WriteLine("Users: {0}", moviesContext.Users.Count()); Console.WriteLine("Ratings: {0}", moviesContext.Ratings.Count()); Console.WriteLine("Movies: {0}", moviesContext.Movies.Count()); }
public JsonResult GetMovieById(string id) { using (MoviesEntities entity = new MoviesEntities()) { var movieId = Convert.ToInt32(id); var searchMovie = entity.Movies.Find(movieId); return(Json(searchMovie, JsonRequestBehavior.AllowGet)); } }
public ActionResult EditActor(String id) { using (MoviesEntities entities = new MoviesEntities()) { var Id = Int32.Parse(id); var user = entities.Actors.FirstOrDefault(x => x.Id == Id); return(View(user)); } }
public Movy GetRandomMovieByCat(string catName) { MoviesEntities ORM = new MoviesEntities(); List <Movy> movieLst = (from m in ORM.Movies where m.Category == catName select m).ToList(); return(movieLst[randNum.Next(movieLst.Count)]); }
public ActionResult Add(Actor actor) { using (MoviesEntities entities = new MoviesEntities()) { entities.Actors.Add(actor); entities.SaveChanges(); } ViewBag.Added = " New Actor Has been Added "; return(View()); }
public List <MovieList> GetMoviesByCategory(string id) { MoviesEntities db = new MoviesEntities(); List <MovieList> Movies = (from p in db.MovieLists where p.Category.Contains(id) select p).ToList(); return(Movies); }
static void Main() { var context = new MoviesEntities(); //1. Adult Movies //Export all adult movies. Order them by title and by ratings received as secondary criteria. //Select each movie's title and the number of ratings received. var adultMovies = context.Movies .Where(m => m.AgeRestriction == AgeRestriction.Adult) .OrderBy(m => m.Title) .ThenByDescending(m => m.Ratings.Count) .Select(m => new { title = m.Title, ratingsGiven = m.Ratings.Count }); string adultMoviesJson = JsonConvert.SerializeObject(adultMovies, Newtonsoft.Json.Formatting.Indented); File.WriteAllText("../../adult-movies.json", adultMoviesJson); // Query 2.Rated Movies by User: var ratedMoviesByUser = context.Users .Where(u => u.Username == "jmeyery") .Select(u => new { username = u.Username, ratedMovies = u.Ratings .OrderBy(r => r.Movie.Title) .Select(r => new { title = r.Movie.Title, userRating = r.Stars, averageRating = r.Movie.Ratings.Average(rStars => rStars.Stars) }) }); string ratedMoviesByUserJson = JsonConvert.SerializeObject(ratedMoviesByUser, Newtonsoft.Json.Formatting.Indented); File.WriteAllText("../../rated-movies-by-jmeyery.json", ratedMoviesByUserJson); //// Query 3.Top 10 Favourite Movies: var favouriteMovies = context.Movies .Where(m => m.AgeRestriction == AgeRestriction.Teen) .OrderByDescending(m => m.UsersThatMovieIsFavourite.Count) .ThenBy(m => m.Title) .Take(10) .Select(m => new { isbn = m.Isbn, title = m.Title, favouritedBy = m.UsersThatMovieIsFavourite.Select(u => u.Username) }); string favouriteMoviesJson = JsonConvert.SerializeObject(favouriteMovies, Newtonsoft.Json.Formatting.Indented); File.WriteAllText("../../top-10-favourite-movies.json", favouriteMoviesJson); }
public static void Main() { var context = new MoviesEntities(); var js = new JavaScriptSerializer(); ExportAdultMovies(context, js); ExportRatedMoviesByUser(context, js); ExportTopFavouriteMovies(context, js); }
private static void ExportRatedMoviesByUser(MoviesEntities context, JavaScriptSerializer js) { var ratedMoviesByUser = context.Users .Select(u => new { username = u.Username, ratedMovies = u.Movies.Where(m => m.Ratings.Count > 0) // no idea }); var output = js.Serialize(ratedMoviesByUser); //File.AppendAllText(@"..\..\Results\rated-movies-by-jmeyery.json", output); //Console.WriteLine("Export rated-movies-by-jmeyery.json complited!"); }
static void Main() { var db = new MoviesEntities(); var movies = db.Movies.Where(m => m.AgeRestriction == AgeRestriction.Teen).Select(m => new { m.Isbn, m.Title, favouriteBy = m.Users.Select(u => u.Username) }) .Take(10); foreach (var movie in movies) { Console.WriteLine(movie.Isbn + " " + movie.Title + " " + string.Join(", ", movie.favouriteBy)); } }
private static void ExportAdultMovies(MoviesEntities context, JavaScriptSerializer js) { var allAdultMovies = context.Movies .Where(m => m.AgeRestriction == AgeRestriction.Adult) .Select(m => new { title = m.Title, ratingsGiven = m.Ratings.Count }) .OrderBy(m => m.title) .ThenBy(m => m.ratingsGiven); var output = js.Serialize(allAdultMovies); File.AppendAllText(@"..\..\Results\adult-movies.json", output); Console.WriteLine("Export adult-movies.json complited!"); }
private static void ExportTopFavouriteMovies(MoviesEntities context, JavaScriptSerializer js) { var topTenFavouriteTeenMovies = context.Movies .Where(m => m.AgeRestriction == AgeRestriction.Teen) .Select(m => new { isbn = m.Isbn, title = m.Title, favouritedBy = m.Ratings.Count // no idea }) .OrderByDescending(m => m.favouritedBy) .ThenBy(m => m.title) .Take(10); var output = js.Serialize(topTenFavouriteTeenMovies); //File.AppendAllText(@"..\..\Results\top-10-favourite-movies.json", output); //Console.WriteLine("Export top-10-favourite-movies.json complited!"); }
private static void ActorsAndMovies() { Console.WriteLine(); using (MoviesEntities ctx = new MoviesEntities()) { var actors = from a in ctx.Actors select a; foreach (var a in actors) { Console.WriteLine("{0} {1}", a.FirstName, a.LastName); Console.WriteLine(new String('-', 30)); foreach(var m in a.Filmographies) { Console.WriteLine("{0}", m.Movie.Title); } Console.WriteLine(); } } }
public PersonRepository() { db = new MoviesEntities(); }
public MoviesRepository() { db = new MoviesEntities(); MoviesEntities asd = new MoviesEntities(); }
private static void MovieSchedules() { Console.WriteLine(); using (MoviesEntities ctx = new MoviesEntities()) { var sched = from s in ctx.MovieSchedules join m in ctx.Movies on s.MovieID equals m.MovieID join t in ctx.Theaters on s.TheaterID equals t.TheaterID orderby t.NameOfTheater, s.StartDateAndTime descending select new { TheaterName = t.NameOfTheater, Time = s.StartDateAndTime, Title = m.Title }; foreach (var s in sched) { Console.WriteLine("{0} {1}\n{2}", s.TheaterName, s.Time, s.Title); Console.WriteLine(); } } }