public HttpResponseMessage AddComment(string sessionKey, string movieTitle, CommentModel comment) { try { var context = new MoviesContext(); var user = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey); if (user == null) { throw new ArgumentException("Invalid authentication!"); } var movie = context.Movies.FirstOrDefault(m => m.Title == movieTitle); if (movie == null) { throw new ArgumentException("Movie not found!"); } var newComment = new Comment() { Text = comment.Text, UserName = user.Username }; movie.Comments.Add(newComment); context.SaveChanges(); var response = this.Request.CreateResponse(HttpStatusCode.OK, newComment); return response; } catch (Exception ex) { var response = this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return response; } }
public AccountController() { var context = new MoviesContext(); userRole = context.Roles .Where(r => r.Name == "user") .Select(r => r.Id) .FirstOrDefault() .ToString(); IdentityManager = new AuthenticationIdentityManager(new IdentityStore(context)); }
public HttpResponseMessage AddMovie(string sessionKey, AddMovieModel movie) { try { var context = new MoviesContext(); var user = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey); if (user == null || user.IsAdmin==false) { throw new ArgumentException("You don't have permissions to add movies!"); } var newMovie = new Movie() { Title = movie.Title, Description = movie.Description, CoverUrl = movie.CoverUrl }; if (movie.Categories==null || movie.Categories.Count()==0) { throw new ArgumentException("Movie must have categories!"); } foreach (var category in movie.Categories) { var cat = context.Categories.FirstOrDefault(c => c.Name == category.Name); if(cat==null) { context.Categories.Add(new Category() { Name = category.Name }); context.SaveChanges(); cat = context.Categories.FirstOrDefault(c => c.Name == category.Name); } newMovie.Categories.Add(cat); } context.Movies.Add(newMovie); context.SaveChanges(); var response = this.Request.CreateResponse(HttpStatusCode.OK); return response; } catch (Exception ex) { var response = this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return response; } }
public HttpResponseMessage PostLoginUser(UserModel model) { try { ValidateUsername(model.Username); var context = new MoviesContext(); using (context) { var user = context.Users.FirstOrDefault(u => u.Username == model.Username && u.AuthCode == model.AuthCode); if (user == null) { throw new InvalidOperationException("Invalid username or password"); } if (user.SessionKey == null) { user.SessionKey = this.GenerateSessionKey(user.Id); context.SaveChanges(); } var loggedModel = new LoggedUserModel() { Username = model.Username, FirstName = model.FirstName, LastName = model.LastName, IsAdmin = user.IsAdmin, SessionKey = user.SessionKey }; var response = this.Request.CreateResponse(HttpStatusCode.Created, loggedModel); return response; } } catch (Exception ex) { var response = this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return response; } }
static void Main() { var context = new MoviesContext(); var movies = context.Movies .Where(m => m.AgeRestriction == AgeRestriction.Teen) .OrderByDescending(m => m.Users.Count) .ThenBy(m => m.Title) .Select(m => new { isbn = m.Isbn, title = m.Title, favouritedBy = m.Users .Select(u => u.Username) }) .Take(10); string json = JsonConvert.SerializeObject(movies, Formatting.Indented); File.WriteAllText("../../top-10-favourite-movies.json", json); }
public MoviesViewComponent(MoviesContext moviesContext) { _moviesContext = moviesContext; }
public MovieController(MoviesContext context) { _context = context; }
private static User calculateUserModel() { var list = new List <Model>(); using (var db = new MoviesContext()) { var models = db.models; foreach (var rating in db.ratings) { var model = models.ToList().Where(m => m.movie == rating.movie).First(); list.Add(weight(model, (float)(rating.rating / 10.0))); } } var rng = new Random(); var result = new User() { values1 = (float)rng.NextDouble(), values2 = (float)rng.NextDouble(), values3 = (float)rng.NextDouble(), values4 = (float)rng.NextDouble(), values5 = (float)rng.NextDouble(), values6 = (float)rng.NextDouble(), values7 = (float)rng.NextDouble(), values8 = (float)rng.NextDouble(), values9 = (float)rng.NextDouble(), values10 = (float)rng.NextDouble(), values11 = (float)rng.NextDouble(), values12 = (float)rng.NextDouble(), values13 = (float)rng.NextDouble(), values14 = (float)rng.NextDouble(), values15 = (float)rng.NextDouble(), values16 = (float)rng.NextDouble(), values17 = (float)rng.NextDouble(), values18 = (float)rng.NextDouble() }; if (list.Any()) { result = new User() { values1 = list.Select(m => m.values1).Average(), values2 = list.Select(m => m.values2).Average(), values3 = list.Select(m => m.values3).Average(), values4 = list.Select(m => m.values4).Average(), values5 = list.Select(m => m.values5).Average(), values6 = list.Select(m => m.values6).Average(), values7 = list.Select(m => m.values7).Average(), values8 = list.Select(m => m.values8).Average(), values9 = list.Select(m => m.values9).Average(), values10 = list.Select(m => m.values10).Average(), values11 = list.Select(m => m.values11).Average(), values12 = list.Select(m => m.values12).Average(), values13 = list.Select(m => m.values13).Average(), values14 = list.Select(m => m.values14).Average(), values15 = list.Select(m => m.values15).Average(), values16 = list.Select(m => m.values16).Average(), values17 = list.Select(m => m.values17).Average(), values18 = list.Select(m => m.values18).Average() }; } return(result); }
public ActorsRepository(MoviesContext dbContext) : base(dbContext) { }
public DirectorService(MoviesContext db) { _db = db; }
public HttpResponseMessage MarkWatched(string sessionKey, int movieId) { try { var context = new MoviesContext(); var user = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey); if (user == null) { throw new ArgumentException("Invalid authentication!"); } var movie = context.Movies.FirstOrDefault(m => m.Id == movieId); if(movie==null) { throw new ArgumentException("Movie not found!"); } var watched = context.Watches.FirstOrDefault(w => w.Movie.Id == movieId && w.User.Id == user.Id); if(watched!=null) { throw new Exception("You have already added this movie to watched!"); } movie.WhachedBy.Add(new Watches() { Movie = movie, User = user }); context.SaveChanges(); var response = this.Request.CreateResponse(HttpStatusCode.OK); return response; } catch (Exception ex) { var response = this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return response; } }
public MoviesController(MoviesContext context, ILogger <HomeController> logger, IMapper mapper) { _context = context; _logger = logger; _mapper = mapper; }
public HttpResponseMessage PostRegisterUser(UserModel model) { try { var dbContext = new MoviesContext(); using (dbContext) { this.ValidateUsername(model.Username); this.ValidateFirstname(model.FirstName); this.ValidateLastname(model.LastName); var user = dbContext.Users.FirstOrDefault(u => u.Username.ToLower() == model.Username.ToLower()); if (user != null) { throw new InvalidOperationException("Users exists"); } user = new User() { Username = model.Username, FirstName = model.FirstName, LastName = model.LastName, AuthCode = model.AuthCode, IsAdmin = false }; dbContext.Users.Add(user); dbContext.SaveChanges(); user.SessionKey = this.GenerateSessionKey(user.Id); dbContext.SaveChanges(); var loggedModel = new LoggedUserModel() { Username = model.Username, FirstName = model.FirstName, LastName = model.LastName, IsAdmin = false, SessionKey = user.SessionKey }; var response = this.Request.CreateResponse(HttpStatusCode.Created, loggedModel); return response; } } catch (Exception ex) { var response = this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return response; } }
public HttpResponseMessage PutLogoutUser(string sessionKey) { try { var context = new MoviesContext(); using (context) { var user = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey); if (user == null) { throw new ArgumentException("Invalid user authentication."); } user.SessionKey = null; context.SaveChanges(); var response = this.Request.CreateResponse(HttpStatusCode.OK); return response; } } catch (Exception ex) { var response = this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return response; } }
public HttpResponseMessage Vote(string sessionKey, int movieId, int vote) { try { var context = new MoviesContext(); var user = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey); if (user == null) { throw new ArgumentException("Invalid authentication!"); } var movie = context.Movies.FirstOrDefault(m => m.Id == movieId); if (movie == null) { throw new ArgumentException("Movie not found!"); } if(vote<1 || vote>10) { throw new ArgumentException("Invalid vote!"); } if(movie.Votes.Any(v=>v.User.Id==user.Id && v.Movie.Id==movieId)) { throw new Exception("You have voted for this movie!"); } if(movie.Rating==null || movie.Rating==0) { movie.Rating = vote; movie.Votes.Add(new Vote() { Movie = movie, User = user, Rate = vote }); } else { movie.Rating = (movie.Rating + vote)/2; movie.Votes.Add(new Vote() { Movie = movie, User = user, Rate = vote }); } context.SaveChanges(); var response = this.Request.CreateResponse(HttpStatusCode.OK); return response; } catch (Exception ex) { var response = this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return response; } }
public MoviesController(MoviesContext dbContext) { _dbContext = dbContext; }
public MovieService() { this.moviesContext = new MoviesContext(); }
public ReviewsService(MoviesContext moviesContext) { this.moviesContext = moviesContext; }
public HomeController(ILogger <HomeController> logger, MoviesContext context) { _logger = logger; _context = context; }
public MoviesService(MoviesContext moviesContext) { _moviesContext = moviesContext; }
public HttpResponseMessage GetWatchedMovies(string sessionKey, int page = 1) { try { var context = new MoviesContext(); var user = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey); if (user == null) { throw new ArgumentException("Invalid authentication!"); } page = (page - 1) * 20; var moviesEntity = context.Movies.Where(m => m.WhachedBy.Any(w => w.User.Id == user.Id)).OrderByDescending( m => m.Rating) .Skip(page).Take(20).ToList(); var movies = from movie in moviesEntity select new SimpleMovieModel() { Id = movie.Id, Title = movie.Title, /*Description = movie.Description, CoverUrl = movie.CoverUrl, Rating = movie.Rating, Categories = from category in movie.Categories select new CategoryModel() { Name = category.Name }, Comments = from comment in movie.Comments select new CommentModel() { Text = comment.Text, UserName = comment.UserName }, UsersWhoVoted = from theUser in movie.UsersWhoVoted select new UserModel() { FirstName = theUser.FirstName, LastName = theUser.LastName, Username = theUser.Username }*/ }; var response = this.Request.CreateResponse(HttpStatusCode.OK, movies); return response; } catch (Exception ex) { var response = this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return response; } }
public MoviesController() { var context = new MoviesContext(); this.movieService = new MovieService(context); this.genreService = new GenreService(context); }
public MoviesApiController(MoviesContext context, IMapper mapper) { _context = context; _mapper = mapper; }
public CineplexesController(MoviesContext context) { _context = context; }
public StudioRepository(MoviesContext context) : base(context) { }
public MoviesContextBuilder(string databaseName = null) { _context = new MoviesContext(CreateInMemoryOptions(databaseName)); }
public ShowsRepository(MoviesContext context) { this.context = context; }
// GET: api/link public IActionResult Link(string term) { var moviesFile = System.IO.File.Open("movies.csv", FileMode.Open); var modelFile = System.IO.File.Open("X-results.csv", FileMode.Open); using (TextReader moviesReader = new StreamReader(moviesFile)) { using (TextReader modelReader = new StreamReader(modelFile)) { var movies = new CsvReader(moviesReader); var moviesRecords = movies.GetRecords <csvMovie>().ToList(); var models = new CsvReader(modelReader); var modelsRecords = models.GetRecords <csvModel>().ToList(); foreach (var name in DataDict.Keys) { var title = name.ToLower(); if (title.Split(' ').First().ToLower() == "the") { title = title.Remove(0, 4); } var rows = moviesRecords.Where(r => r.title.ToLower().Contains(title)); if (rows.Any()) { var row = rows.First(); using (var db = new MoviesContext()) { var model = modelsRecords[int.Parse(row.movieId) - 1]; var dbModel = new Model() { movie = name, values1 = float.Parse(model.values1), values2 = float.Parse(model.values2), values3 = float.Parse(model.values3), values4 = float.Parse(model.values4), values5 = float.Parse(model.values5), values6 = float.Parse(model.values6), values7 = float.Parse(model.values7), values8 = float.Parse(model.values8), values9 = float.Parse(model.values9), values10 = float.Parse(model.values10), values11 = float.Parse(model.values11), values12 = float.Parse(model.values12), values13 = float.Parse(model.values13), values14 = float.Parse(model.values14), values15 = float.Parse(model.values15), values16 = float.Parse(model.values16), values17 = float.Parse(model.values17), values18 = float.Parse(model.values18) }; db.models.Add(dbModel); var dbMovie = db.movies.Where(m => m.name == name).First(); dbMovie.genre = row.genres; db.SaveChanges(); } } } } } return(Ok("Done")); }
public CountryRepository(MoviesContext context) : base(context) { }
public CareerRepository(MoviesContext context) : base(context) { }
// GET: /<controller>/ //public IActionResult Index() //{ // return View(); //} public Home(MoviesContext context) { _moviesContext = context; }
public CastAndCrewRepository(MoviesContext context) : base(context) { }
public MovieController(MoviesContext db, UserManager <User> userManager) { context = db; _userManager = userManager; }
public IEnumerable <Movie> Get(string name) { var db = new MoviesContext(); return(db.Movie.Where(x => x.Title.Contains(name)).ToList()); }
public SessionModelsController(MoviesContext context) { _context = context; }
public GenreRepository(MoviesContext context) : base(context) { }
public WishlistController(MoviesContext context) { _context = context; }
public MovieController(MoviesContext movieContext, IMovieService service) { _movieContext = movieContext; _service = service; }
public MoviesApi_IntegrationTests(MyFixture5 myFixture) { api_ = myFixture.Api; contx_ = myFixture.Resolve <MoviesContext>(); }
//Class to initialise the dataset public static void Initialise(MoviesContext context) { //Checks to see if any movies have been added, if they have then the database has already been initialised and we should return if (context.Movies.Any()) { return; } var genresToAdd = new Genre[] { new Genre { GenreName = "Thriller" }, new Genre { GenreName = "Comedy" }, new Genre { GenreName = "SciFi" }, new Genre { GenreName = "Action" }, new Genre { GenreName = "Drama" }, new Genre { GenreName = "History" }, new Genre { GenreName = "Documentary" }, }; foreach (Genre m in genresToAdd) { context.Genres.Add(m); } context.SaveChanges(); var moviesToAdd = new Movie[] { new Movie { Title = "The Shawshank Redemption", ReleaseYear = new DateTime(1994, 1, 1), RunningTime = 142 }, new Movie { Title = "The Godfather", ReleaseYear = new DateTime(1972, 1, 1), RunningTime = 175 }, new Movie { Title = "The Godfather - Part II", ReleaseYear = new DateTime(1974, 1, 1), RunningTime = 202 }, new Movie { Title = "Pulp Fiction", ReleaseYear = new DateTime(1994, 1, 1), RunningTime = 154 } }; foreach (Movie m in moviesToAdd) { context.Movies.Add(m); } context.SaveChanges(); var shawshankId = context.Movies.Single(x => x.Title == "The Shawshank Redemption").Id; var godfatherId = context.Movies.Single(x => x.Title == "The Godfather").Id; var godfather2Id = context.Movies.Single(x => x.Title == "The Godfather - Part II").Id; var pulpFictionId = context.Movies.Single(x => x.Title == "Pulp Fiction").Id; var thrillerId = context.Genres.Single(x => x.GenreName == "Thriller").Id; var comedyId = context.Genres.Single(x => x.GenreName == "Comedy").Id; var sciFiId = context.Genres.Single(x => x.GenreName == "SciFi").Id; var actionId = context.Genres.Single(x => x.GenreName == "Action").Id; var dramaId = context.Genres.Single(x => x.GenreName == "Drama").Id; var historyId = context.Genres.Single(x => x.GenreName == "History").Id; var docoId = context.Genres.Single(x => x.GenreName == "Documentary").Id; var movieGenresToAdd = new MovieGenre[] { new MovieGenre { MovieId = shawshankId, GenreId = thrillerId }, new MovieGenre { MovieId = godfatherId, GenreId = thrillerId }, new MovieGenre { MovieId = godfatherId, GenreId = actionId }, new MovieGenre { MovieId = godfatherId, GenreId = dramaId }, new MovieGenre { MovieId = godfather2Id, GenreId = historyId }, new MovieGenre { MovieId = godfather2Id, GenreId = dramaId }, }; foreach (MovieGenre mg in movieGenresToAdd) { context.MovieGenres.Add(mg); } context.SaveChanges(); }
static void Main(string[] args) { var context = new MoviesContext(); var Movieclass = new Movie(); Console.WriteLine("Please enter MovieNo: "); var userMovieNo = Convert.ToInt32(Console.ReadLine()); var numberofActors = Movieclass.NumActors(context, userMovieNo); Console.WriteLine(numberofActors); Console.WriteLine("To check a Movie's age please enter the Movie No: "); var userMovieAgeCheck = Convert.ToInt16(Console.ReadLine()); var movieAgeResult = Movieclass.GetAge(context, userMovieAgeCheck); Console.WriteLine($"The movie is {movieAgeResult} years old."); List <Movie> movieList = context.Movies.ToList(); foreach (Movie moobie in movieList) { Console.WriteLine(moobie.Title, moobie.Runtime); } var moviesearch = from movienames in context.Movies where movienames.Title.StartsWith("The") select movienames; List <Movie> moobiess = moviesearch.ToList(); foreach (Movie mooovie in moobiess) { Console.WriteLine(mooovie.Title); } Console.WriteLine("Please enter Movie Title: "); var userupdateMovieselection = Console.ReadLine(); Console.WriteLine("Please enter the new title for the movie: "); var Movieuserupdatemovie = Console.ReadLine(); var moviequery2 = from Movie in context.Movies where Movie.Title.StartsWith(userupdateMovieselection) select Movie; var moviequery2result = moviequery2.FirstOrDefault <Movie>(); moviequery2result.Title = Movieuserupdatemovie; context.SaveChanges(); // ///b Console.WriteLine("Please enter the actor's fullname: "); var updateactorsname = Console.ReadLine(); Console.WriteLine("Please enter the new first name for the actor: "); var updateactorfirstname = Console.ReadLine(); Console.WriteLine("Please enter the new SURNAME for the actor: "); var updateactorsurname = Console.ReadLine(); var updateactornamequery = from Actor in context.Actors where Actor.Fullname.StartsWith(updateactorsname) select Actor; var updateactornamequeryresult = updateactornamequery.FirstOrDefault <Actor>(); updateactornamequeryresult.Givenname = updateactorfirstname; updateactornamequeryresult.Surname = updateactorsurname; context.SaveChanges(); Console.WriteLine("Please add new title: "); var addnewMovieTitle = Console.ReadLine(); Console.WriteLine("Please add new Release year: "); var addnewMovieRelyear = Convert.ToInt16(Console.ReadLine()); Console.WriteLine("Please add new movienumber: "); var addnewMovieNumber = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Please add new Run Time: "); var addnewMovierunTime = Convert.ToInt16(Console.ReadLine()); Movie useraddMovie = new Movie { Title = addnewMovieTitle, Movieno = addnewMovieNumber, Relyear = addnewMovieRelyear, Runtime = addnewMovierunTime }; context.Movies.AddRange(useraddMovie); context.SaveChanges(); Console.WriteLine("Please add a new Actor given name: "); var addnewActorgivenname = Console.ReadLine(); Console.WriteLine("Please add new Actor surname : "); var addnewActorSurname = (Console.ReadLine()); Console.WriteLine("Please add new actor number: "); var addnewActorNumber = Convert.ToInt32(Console.ReadLine()); Actor useraddActor = new Actor { Givenname = addnewActorgivenname, Surname = addnewActorSurname, Actorno = addnewActorNumber, Fullname = ($"{addnewActorgivenname} {addnewActorSurname}") }; context.Actors.AddRange(useraddActor); context.SaveChanges(); Console.WriteLine("Pleas enter the actor number to be cast: "); var castnewActorNo = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Pleas search for the movie number to be cast into: "); var castnewActorMOVIENo = Convert.ToInt32(Console.ReadLine()); var castingsearch = context.Castings.OrderByDescending(u => u.Castid).FirstOrDefault(); Casting userCasting = new Casting { Actorno = castnewActorNo, Movieno = castnewActorMOVIENo, Castid = (castingsearch.Castid + 1) }; context.Castings.AddRange(userCasting); context.SaveChanges(); }
public GenreService(MoviesContext context) { this.moviesContext = context; }
public RealisatorRepository(MoviesContext dbContext) : base(dbContext) { }
public MovieService(MoviesContext moviesContext) { this.moviesContext = moviesContext; }
public HttpResponseMessage GetSingleMovie(string sessionKey, int id) { try { var context = new MoviesContext(); var user = context.Users.FirstOrDefault(u => u.SessionKey == sessionKey); if (user == null) { throw new ArgumentException("Invalid authentication!"); } var moviesEntity = context.Movies.FirstOrDefault(m => m.Id == id); var movies = new MovieModel() { Title = moviesEntity.Title, Description = moviesEntity.Description, CoverUrl = moviesEntity.CoverUrl, Rating = moviesEntity.Rating, /*Categories = from theCategory in movie.Categories select new CategoryModel() { Name = theCategory.Name }, Comments = from comment in movie.Comments select new CommentModel() { Text = comment.Text, UserName = comment.UserName }, UsersWhoVoted = from theUser in movie.UsersWhoVoted select new UserModel() { FirstName = theUser.FirstName, LastName = theUser.LastName, Username = theUser.Username }*/ }; var response = this.Request.CreateResponse(HttpStatusCode.OK, movies); return response; } catch (Exception ex) { var response = this.Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message); return response; } }