public IMovieMapper Get_Movie_by_ID(IMovieMapper movie) { IMovieMapper output = null; //Check for null or empty values: var testVars = new Object[] { movie.Id }; if (!DataValidator.is_null_empty_or_zero(testVars)) { try { //Insert the movie: output = moviesDAL.Get_Movie_by_ID(movie); } catch (SqlDALException e) { throw new SqlBLLException("One or more SQL constraints may have caused this issue. Please provide the movie ID.", e); } } else { throw new MissingDataBLLException("Cannot complete this operation because required data is missing. Please be sure to provide movie ID."); } return(output); }
public MovieService(IMovieRepositoryReadOnly movieRepositoryReadOnly, IMovieMapper movieMapper, IMovieRepository movieRepository, IMovieRateRepository movieRateRepository) { _movieRepositoryReadOnly = movieRepositoryReadOnly; _movieMapper = movieMapper; _movieRepository = movieRepository; _movieRateRepository = movieRateRepository; }
public IMovieMapper Update(IMovieMapper movie) { IMovieMapper output = null; //Check for null or empty values: var testVars = new Object[] { movie.Id, movie.Title, movie.RunTime, movie.Image }; if (!DataValidator.is_null_empty_or_zero(testVars)) { try { //Insert the movie: output = moviesDAL.Update(movie); } catch (SqlDALException e) { throw new SqlBLLException("One or more SQL constraints may have caused this issue. Please be sure the Title field is unique and all other data is valid.", e); } } else { throw new MissingDataBLLException("Cannot complete this operation because required data is missing. Please be sure to provide movieId, title, runtime, and image."); } return(output); }
public IMovieMapper Update(IMovieMapper movie) { IMovieMapper output = null; try { using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("update_movie", connection)) { command.CommandType = CommandType.StoredProcedure; //Add input parameters: command.Parameters.Add("@MovieID", SqlDbType.Int).Value = movie.Id; command.Parameters.Add("@Title", SqlDbType.VarChar).Value = movie.Title; command.Parameters.Add("@RunTime", SqlDbType.Int).Value = movie.RunTime; command.Parameters.Add("@Image", SqlDbType.VarChar).Value = movie.Image; command.Prepare(); int rowsAffected = command.ExecuteNonQuery(); //Run the query. if (rowsAffected == 1) { output = movie; } } } } catch (SqlException e) { throw new SqlDALException("There was a problem with SQL. Please provide valid data. The MovieId, Title, Runtime, and Image fields must be provided. The Title field must be unique.", e); } return(output); }
public void Get_ShowTimes_by_MovieID() { //Insert a movie: IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png" }); //Create some showtimes: IShowTimesMapper showtime1 = new ShowTimesMapper { ShowingDateTime = new DateTime(2017, 01, 20, 13, 01, 05) }; IShowTimesMapper showtime2 = new ShowTimesMapper { ShowingDateTime = new DateTime(2016, 01, 20, 13, 01, 05) }; IShowTimesMapper showtime3 = new ShowTimesMapper { ShowingDateTime = new DateTime(2015, 01, 20, 13, 01, 05) }; //Insert the showtimes: movies_bll.InsertShowTime(movie1, showtime1); movies_bll.InsertShowTime(movie1, showtime2); movies_bll.InsertShowTime(movie1, showtime3); //Get the showtimes back out of the database: List <IShowTimesMapper> found_showtimes = movies_bll.Get_ShowTimes_by_MovieID(movie1); //Assert Assert.IsTrue(found_showtimes.Count == 3); }
public void InsertShowTime() { //Create a movie: IMovieMapper movie1 = movies_dal.InsertMovie(new MovieMapper { Title = "Pulp Fiction 2: Pulpier Fiction", RunTime = 130, Image = "/path/to/image/pf2.png" }); //Add a showtime to a movie: //DateTime Constructor for reference: //public DateTime( // int year, // int month, // int day, // int hour, // int minute, // int second //) IShowTimesMapper showtime1 = movies_dal.InsertShowTime(movie1, new ShowTimesMapper { ShowingDateTime = new DateTime(2017, 01, 20, 13, 01, 05) }); Assert.IsNotNull(showtime1); //Get the show times by movieId List <IShowTimesMapper> showtimes = movies_dal.Get_ShowTimes_by_MovieID(new MovieMapper { Id = movie1.Id }); Assert.IsTrue(showtimes.Count == 1); }
public void Search_Movie_by_Name_Like_missing_Name() { //Insert some movies: IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future I", RunTime = 130, Image = "/path/to/image/bttf1.png" }); IMovieMapper movie2 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png" }); IMovieMapper movie3 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future III", RunTime = 130, Image = "/path/to/image/bttf3.png" }); IMovieMapper movie4 = movies_bll.InsertMovie(new MovieMapper { Title = "Future World", RunTime = 130, Image = "/path/to/image/fw.png" }); //Insert some movies without the word "future": IMovieMapper movie5 = movies_bll.InsertMovie(new MovieMapper { Title = "The Matrix", RunTime = 130, Image = "/path/to/image/matrix.png" }); IMovieMapper movie6 = movies_bll.InsertMovie(new MovieMapper { Title = "Braveheart", RunTime = 130, Image = "/path/to/image/bh.png" }); //System.Threading.Thread.Sleep(5000); //Need this because the Search_Movie_by_Name method takes time. //Get the showtimes back out of the database: List <IMovieMapper> found_movies = movies_bll.Search_Movie_by_Name_Like(""); //Assert Assert.IsTrue(found_movies.Count == 0); }
public GetMovieHandler(ICacheMovieRepository movieCacheRepository, ICacheImageRepository imageRepository, IMovieMapper movieMapper, ILogger <GetMovieHandler> logger) { _movieCacheRepository = movieCacheRepository; _imageRepository = imageRepository; _movieMapper = movieMapper; _logger = logger; }
public void Search_Movie_by_Name_Like() { //Create some movies: IMovieMapper movie1 = movies_dal.InsertMovie(new MovieMapper { Title = "Kill Bill 2", RunTime = 130, Image = "/path/to/image/kb2.png" }); IMovieMapper movie2 = movies_dal.InsertMovie(new MovieMapper { Title = "To Kill a Mockingbird", RunTime = 130, Image = "/path/to/image/kadf.png" }); IMovieMapper movie3 = movies_dal.InsertMovie(new MovieMapper { Title = "Back to the Future", RunTime = 130, Image = "/path/to/image/bttf.png" }); IMovieMapper movie4 = movies_dal.InsertMovie(new MovieMapper { Title = "Natural Born Killers", RunTime = 130, Image = "/path/to/image/bttf.png" }); IMovieMapper movie5 = movies_dal.InsertMovie(new MovieMapper { Title = "Into The Wild", RunTime = 130, Image = "/path/to/image/itw.png" }); //System.Threading.Thread.Sleep(5000); //Need this because the Search_Movie_by_Name method takes time. List <IMovieMapper> searchResults = movies_dal.Search_Movie_by_Name_Like("to the"); Assert.IsTrue(searchResults.Count == 2); }
public bool DeleteMovie(IMovieMapper movie) { bool output = false; try { using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("delete_movie", connection)) { command.CommandType = CommandType.StoredProcedure; //Add input parameters: command.Parameters.Add("@MovieID", SqlDbType.Int).Value = movie.Id; //Setup output parameter for the returned Movie.Id: SqlParameter RowsAffected = command.Parameters.Add("@RowsAffected", SqlDbType.Int); RowsAffected.Value = null; RowsAffected.Direction = ParameterDirection.Output; command.Prepare(); command.ExecuteNonQuery(); //Run the query. //Return a boolean to let us know if the delete was successful: output = (((int)RowsAffected.Value) == 1)?true:false; } } } catch (SqlException e) { throw new SqlDALException("There was a problem with SQL. Please provide valid data. The MovieId field must be provided and must exist in the database.", e); } return(output); }
public void Get_Movie_by_ID_nonexisting_movieID() { IMovieMapper found_movie = movies_bll.Get_Movie_by_ID(new MovieMapper { Id = 10001 }); Assert.IsNull(found_movie); }
public void Insert() { IMovieMapper movie1 = movies_dal.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf.png" }); Assert.IsNotNull(movie1); }
public void Update_nonexisting_movie() { //Try to update movie.ID = 10001 (doesn't exist): IMovieMapper updatedMovie = movies_bll.Update(new MovieMapper { Id = 10001, Title = "Back To The Future III", RunTime = 135, Image = "/path/to/image/bttf2_large.png" }); Assert.IsNull(updatedMovie); }
public void Insert_already_existing_Title() { IMovieMapper movie1 = movies_dal.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf.png" }); IMovieMapper movie2 = movies_dal.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 160, Image = "/path/to/image/bttf2.png" }); }
public void DeleteMovie() { //Insert a movie: IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png" }); bool deleted = movies_bll.DeleteMovie(movie1); Assert.IsTrue(deleted); }
public void Update_missing_Image() { //Insert a movie: IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png" }); IMovieMapper updatedMovie = movies_bll.Update(new MovieMapper { Id = movie1.Id, Title = "Back To the Future II", RunTime = 130, Image = "" }); }
public void InsertShowTime_missing_ShowingDateTime() { //Insert a movie: IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png" }); IShowTimesMapper showtime1 = new ShowTimesMapper { ShowingDateTime = new DateTime() }; //Try to insert minValue DateTime (empty datetime). IShowTimesMapper returned_showtime = movies_bll.InsertShowTime(movie1, showtime1); }
public void Get_Movie_by_ID() { //Insert a movie: IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png" }); IMovieMapper found_movie = movies_bll.Get_Movie_by_ID(movie1); Assert.AreEqual(movie1.Title, found_movie.Title); Assert.AreEqual(movie1.RunTime, found_movie.RunTime); Assert.AreEqual(movie1.Image, found_movie.Image); Assert.AreEqual(movie1.Id, found_movie.Id); }
public void Update() { //Insert a movie: IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png" }); IMovieMapper updated_info = new MovieMapper { Id = movie1.Id, Title = "Back To The Future III", RunTime = 135, Image = "/path/to/image/bttf2_large.png" }; IMovieMapper updatedMovie = movies_bll.Update(updated_info); Assert.IsNotNull(updatedMovie); }
public void InsertShowTime() { //Insert a movie: IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png" }); IShowTimesMapper showtime1 = new ShowTimesMapper { ShowingDateTime = new DateTime(2017, 01, 20, 13, 01, 05) }; IShowTimesMapper returned_showtime = movies_bll.InsertShowTime(movie1, showtime1); Assert.IsNotNull(returned_showtime); Assert.IsTrue(returned_showtime.Id > 0); }
public void Get_Movie_by_ID() { //Create a new movie and get its Id: IMovieMapper movie1 = movies_dal.InsertMovie(new MovieMapper { Title = "The Matrix", RunTime = 130, Image = "/path/to/image/braveheart.png" }); //Use the id to get the movie back out: IMovieMapper movie2 = movies_dal.Get_Movie_by_ID(new MovieMapper { Id = movie1.Id }); Assert.IsNotNull(movie2); }
public void Get_All_Movies() { IMovieMapper movie1 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future I", RunTime = 130, Image = "/path/to/image/bttf1.png" }); IMovieMapper movie2 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future II", RunTime = 130, Image = "/path/to/image/bttf2.png" }); IMovieMapper movie3 = movies_bll.InsertMovie(new MovieMapper { Title = "Back To the Future III", RunTime = 130, Image = "/path/to/image/bttf3.png" }); List <IMovieMapper> found_movies = movies_bll.Get_All_Movies(); Assert.AreEqual(found_movies.Count, 3); }
public void Get_All_Movies() { //Create some movies: IMovieMapper movie1 = movies_dal.InsertMovie(new MovieMapper { Title = "The Matrix 2", RunTime = 130, Image = "/path/to/image/matrix2.png" }); IMovieMapper movie2 = movies_dal.InsertMovie(new MovieMapper { Title = "The Matrix 3", RunTime = 130, Image = "/path/to/image/matrix3.png" }); IMovieMapper movie3 = movies_dal.InsertMovie(new MovieMapper { Title = "The Animatrix", RunTime = 130, Image = "/path/to/image/matrix4.png" }); //Get all the movies out of the database: List <IMovieMapper> all_movies = movies_dal.Get_All_Movies(); Assert.IsTrue(all_movies.Count == 3); }
public void DeleteMovie() { //Create a movie: IMovieMapper movie1 = movies_dal.InsertMovie(new MovieMapper { Title = "Pulp Fiction", RunTime = 130, Image = "/path/to/image/pf.png" }); //Delete the movie: Boolean deleted = movies_dal.DeleteMovie(new MovieMapper { Id = movie1.Id }); Assert.IsTrue(deleted); //Use the id to try to get the movie back out (It should be deleted by now): IMovieMapper movie2 = movies_dal.Get_Movie_by_ID(new MovieMapper { Id = movie1.Id }); Assert.IsNull(movie2); }
public void Update() { //Create a new movie and get its Id: IMovieMapper movie1 = movies_dal.InsertMovie(new MovieMapper { Title = "Braveheart", RunTime = 130, Image = "/path/to/image/braveheart.png" }); //Update the movie: IMovieMapper updated_movie = movies_dal.Update(new MovieMapper { Id = movie1.Id, Title = "Braveheart 2: Still Can't Take Muh' Freedom!", RunTime = 300, Image = "/another/path/to/an/image.png" }); //Get the movie out of the database: IMovieMapper foundMovie = movies_dal.Get_Movie_by_ID(new MovieMapper { Id = updated_movie.Id }); Assert.AreEqual(updated_movie.Title, foundMovie.Title); Assert.AreEqual(updated_movie.RunTime, foundMovie.RunTime); Assert.AreEqual(updated_movie.Image, foundMovie.Image); }
//CRUD functionality for 'Movies' table: //Create: public IMovieMapper InsertMovie(IMovieMapper movie) { IMovieMapper output = null; try { using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("insert_Movie", connection)) { command.CommandType = CommandType.StoredProcedure; //Add input parameters: command.Parameters.Add("@Title", SqlDbType.VarChar).Value = movie.Title; command.Parameters.Add("@RunTime", SqlDbType.Int).Value = movie.RunTime; command.Parameters.Add("@Image", SqlDbType.VarChar).Value = movie.Image; //Setup output parameter for the returned Movie.Id: SqlParameter IdentityOutput = command.Parameters.Add("@IdentityOutput", SqlDbType.Int); IdentityOutput.Value = null; IdentityOutput.Direction = ParameterDirection.Output; command.Prepare(); command.ExecuteNonQuery(); //Run the query. //Return the user that was created: output = new MovieMapper(); output.Id = (int)IdentityOutput.Value; output.Title = (String)movie.Title; output.RunTime = (int)movie.RunTime; output.Image = (String)movie.Image; } } } catch (SqlException e) { throw new SqlDALException("There was a problem with SQL. Please provide valid data. The Title, Runtime, and Image fields must be provided. The Title field must be unique.", e); } return(output); }
public IMovieMapper Get_Movie_by_ID(IMovieMapper movie) { IMovieMapper output = null; try { using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("select_movie_by_id", connection)) { command.CommandType = CommandType.StoredProcedure; //Add input parameters: command.Parameters.Add("@MovieID", SqlDbType.Int).Value = movie.Id; //command.ExecuteNonQuery(); //Run the query. command.Prepare(); SqlDataReader movies = command.ExecuteReader(); while (movies.Read()) { //Return the user that was created: output = new MovieMapper(); output.Id = movie.Id; output.Title = (String)movies["Title"]; output.RunTime = (int)movies["RunTime"]; output.Image = (String)movies["Image"]; output.ShowTimes = Get_ShowTimes_by_MovieID(movie); } } } } catch (SqlException e) { throw new SqlDALException("There was a problem with SQL. Please provide valid data. The MovieId field must be provided and must exist in the database.", e); } return(output); }
//CRUD functionality for 'ShowTimes' table: //Create: public IShowTimesMapper InsertShowTime(IMovieMapper movie, IShowTimesMapper showtime) { IShowTimesMapper output = null; try { using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("insert_ShowTime", connection)) { command.CommandType = CommandType.StoredProcedure; //Add input parameters: command.Parameters.Add("@ShowingDateTime", SqlDbType.DateTime).Value = showtime.ShowingDateTime; command.Parameters.Add("@MovieId", SqlDbType.Int).Value = movie.Id; //Setup output parameter for the returned Movie.Id: SqlParameter IdentityOutput = command.Parameters.Add("@IdentityOutput", SqlDbType.Int); IdentityOutput.Value = null; IdentityOutput.Direction = ParameterDirection.Output; command.Prepare(); command.ExecuteNonQuery(); //Run the query. //Return the user that was created: output = new ShowTimesMapper(); output.Id = (int)IdentityOutput.Value; output.ShowingDateTime = (DateTime)showtime.ShowingDateTime; output.MovieId = (int)movie.Id; } } } catch (SqlException e) { throw new SqlDALException("There was a problem with SQL. Please provide valid data. The ShowingDateTime and MovieId fields must be provided.", e); } return(output); }
public List <IShowTimesMapper> Get_ShowTimes_by_MovieID(IMovieMapper movie) { List <IShowTimesMapper> output = new List <IShowTimesMapper>(); try { using (SqlConnection connection = new SqlConnection(ConnectionString)) { connection.Open(); using (SqlCommand command = new SqlCommand("select_all_showtimes_by_movie_id", connection)) { command.CommandType = CommandType.StoredProcedure; //Add input parameters: command.Parameters.Add("@MovieID", SqlDbType.Int).Value = movie.Id; command.Prepare(); SqlDataReader showtimes = command.ExecuteReader(); while (showtimes.Read()) { //Create a new showtime object: ShowTimesMapper showtime = new ShowTimesMapper(); showtime.Id = (int)showtimes["Id"]; showtime.ShowingDateTime = (DateTime)showtimes["ShowingDateTime"]; showtime.MovieId = (int)showtimes["MovieId"]; //Add this new object to a collection: output.Add(showtime); } } } } catch (SqlException e) { throw new SqlDALException("There was a problem with SQL. Please provide valid data. The MovieId field must be provided, and must exist in the database.", e); } return(output); }
public static void OverrideMapper(IMovieMapper mapper) { Mapper = mapper; }
public void Insert_with_empty_Title() { IMovieMapper movie1 = movies_dal.InsertMovie(new MovieMapper { Title = "", RunTime = 130, Image = "/path/to/image/bttf.png" }); }
public MoviesBusinessWorkflow(IMoviesRepository moviesRepository, IMovieMapper movieMapper) { MoviesRepository = moviesRepository; MovieMapper = movieMapper; }