public Response() { Movie = new MovieInfo(); Movies = new List<MovieInfo>(); Actors = new List<Actor>(); Rental = new RentalInfo(); Rentals = new List<RentalInfo>(); }
public MovieInfoVM() { MpaaRatingsList = new List<SelectListItem>(); ActorsList = new List<SelectListItem>(); BorrowersList = new List<SelectListItem>(); DirectorsList = new List<SelectListItem>(); StudiosList = new List<SelectListItem>(); Movie = new MovieInfo(); }
public void AddMovieTest() { List<Actor> actors = new List<Actor>(); Director director = new Director(); Studio studio = new Studio(); var movie = new MovieInfo(); //movie.MovieID = 20; //movie.MpaaRating.FilmRating = "PG-13"; movie.MpaaRating.MpaaRatingID = 7; movie.Title = "Inception"; var actor = new Actor(); actor.ActorID = 6; //actor.FirstName = "Will"; //actor.LastName = "Smith"; actors.Add(actor); movie.Actors = actors; movie.Director.DirectorID = 13; //movie.Director.FirstName = "Oliver"; //movie.Director.LastName = "Queen"; movie.ReleaseDate = 2002; movie.Studio.StudioID = 10; //movie.Studio.StudioName = "Robot"; _response = _ops.AddMovie(movie); var responseReturned = _ops.GetMovieByID(_response.Movie.MovieID); var actual = new JavaScriptSerializer().Serialize(_response.Movie); var expected = new JavaScriptSerializer().Serialize(responseReturned.Movie); //Assert.AreEqual(expected, actual); Assert.AreEqual(true, _response.Success ); }
public void AddMovieWithInputTest() { List<Actor> actors = new List<Actor>(); Director director = new Director(); Studio studio = new Studio(); var movie = new MovieInfo(); //movie.MovieID = 20; movie.MpaaRating.FilmRating = "PG-13"; movie.Title = "Inception"; var actor = new Actor(); //a.ActorID = 10; actor.FirstName = "Will"; actor.LastName = "Smith"; actors.Add(actor); movie.Actors = actors; //movie.Director.DirectorID = 10; movie.Director.FirstName = "Oliver"; movie.Director.LastName = "Queen"; movie.ReleaseDate = 2002; //movie.Studio.StudioID = 10; movie.Studio.StudioName = "Robot"; MovieInfo movieinfo = _repo.AddMovie(movie); var movieReturned = _repo.GetMovieByID(movieinfo.MovieID); var actual = new JavaScriptSerializer().Serialize(movieReturned); var expected = new JavaScriptSerializer().Serialize(movieinfo); Assert.AreEqual(expected, actual); //Assert.AreEqual("Inception", movieinfo.Title); }
public RentalInfo() { Movie = new MovieInfo(); Borrower = new Borrower(); }
public MovieInfo AddMovie(MovieInfo movie) { using (SqlConnection cn = new SqlConnection(Settings.ConnectionString)) { //var p = new DynamicParameters(); //p.Add("@FirstName", movie.Director.FirstName); //p.Add("@LastName", movie.Director.LastName); //p.Add("DirectorID", DbType.Int32, direction: ParameterDirection.Output); //cn.Execute("InsertDirector", p, commandType: CommandType.StoredProcedure); //int directorID = p.Get<int>("DirectorID"); //Console.Write(" New Director Id = {0}", directorID); //var pn = new DynamicParameters(); //pn.Add("@StudioName", movie.Studio.StudioName); //pn.Add("StudioID", DbType.Int32, direction: ParameterDirection.Output); //cn.Execute("InsertStudio", pn, commandType: CommandType.StoredProcedure); //var studioID = pn.Get<int>("StudioID"); //Console.Write("New Studio Id = {0}", studioID); //var pns = new DynamicParameters(); //pns.Add("@FilmRating", movie.MpaaRating.FilmRating); //pns.Add("MPAARatingID", DbType.Int32, direction: ParameterDirection.Output); //cn.Execute("InsertMPAARatings", pns, commandType: CommandType.StoredProcedure); //var mpaaRatingID = pns.Get<int>("MPAARatingID"); //Console.Write("New MPAARating Id = {0}", mpaaRatingID); var pnsm = new DynamicParameters(); pnsm.Add("@MovieTitle", movie.Title); pnsm.Add("@MPAARatingID", movie.MpaaRating.MpaaRatingID); pnsm.Add("@DirectorID", movie.Director.DirectorID); pnsm.Add("@StudioID", movie.Studio.StudioID); pnsm.Add("@ReleaseDate", movie.ReleaseDate); pnsm.Add("MovieID", DbType.Int32, direction: ParameterDirection.Output); cn.Execute("InsertMovies", pnsm, commandType: CommandType.StoredProcedure); var movieID = pnsm.Get<int>("MovieID"); //Console.Write("New Movie Id = {0}", movieID); //var pa = new DynamicParameters(); //foreach (var actor in movie.Actors) //{ // pa.Add("@FirstName", actor.FirstName); // pa.Add("@LastName", actor.LastName); //} //pa.Add("ActorID", DbType.Int32, direction: ParameterDirection.Output); //cn.Execute("InsertActor", pa, commandType: CommandType.StoredProcedure); //var actorID = pa.Get<int>("ActorID"); foreach (var actorID in movie.ActorIDs) { var pma = new DynamicParameters(); pma.Add("@MovieID", movieID); pma.Add("@ActorID", actorID); cn.Execute("InsertMovieActors", pma, commandType: CommandType.StoredProcedure); } return GetMovieByID(movieID); } }
private MovieInfo PopulateMovieInfoFromDataReader(SqlDataReader dr) { var movie = new MovieInfo(); movie.MovieID = (int)dr["MovieID"]; movie.Title = dr["MovieTitle"].ToString(); movie.MpaaRating.FilmRating = dr["FilmRating"].ToString(); movie.Director.DirectorID = (int)dr["DirectorID"]; movie.Director.FirstName = dr["dFirstName"].ToString(); movie.Director.LastName = dr["dLastName"].ToString(); movie.Studio.StudioID = (int) dr["StudioID"]; movie.Studio.StudioName = dr["StudioName"].ToString(); movie.ReleaseDate = (int)dr["ReleaseDate"]; movie.Actors = GetListOfActorsByMovieID(movie.MovieID); return movie; }
public MovieInfo GetMovieByID(int movieID) { MovieInfo movie = new MovieInfo(); using (var cn = new SqlConnection(Settings.ConnectionString)) { var cmd = new SqlCommand(); cmd.CommandText = "select m.MovieID, m.MovieTitle, mpaa.FilmRating, m.ReleaseDate, d.DirectorID, d.FirstName as dFirstName, " + "d.LastName as dLastName, s.StudioName, s.StudioID " + "from Movies m " + "Join Directors d " + "on m.DirectorID = d.DirectorID " + "Join studios s " + "on m.StudioID = s.StudioID " + "join MPAARatings mpaa " + "on m.MPAARatingID = mpaa.MPAARatingID " + "where m.MovieID = @movieID"; cmd.Connection = cn; cmd.Parameters.AddWithValue("@MovieID", movieID); cn.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while (dr.Read()) { movie = PopulateMovieInfoFromDataReader(dr); } } } return movie; }