Example #1
0
        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 IShowTimesMapper InsertShowTime(IMovieMapper movie, IShowTimesMapper showtime)
        {
            IShowTimesMapper output = null;
            //Check for null or empty values:
            var testVars = new Object[] {
                movie.Id,
                showtime.ShowingDateTime
            };

            if (!DataValidator.is_null_empty_or_zero(testVars))
            {
                try
                {
                    //Insert the movie:
                    output = moviesDAL.InsertShowTime(movie, showtime);
                }
                catch (SqlDALException e)
                {
                    throw new SqlBLLException("One or more SQL constraints may have caused this issue.  Please provide the movie.Id and showtime.ShowingDateTime.", e);
                }
            }
            else
            {
                throw new MissingDataBLLException("Cannot complete this operation because required data is missing.  Please be sure to provide movie.Id and showtime.ShowingDateTime.");
            }
            return(output);
        }
 public void InsertShowTime_missing_movieId()
 {
     IMovieMapper movie1 = new MovieMapper {
         Id = 0
     };
     IShowTimesMapper showtime1 = new ShowTimesMapper {
         ShowingDateTime = new DateTime(2017, 01, 20, 13, 01, 05)
     };
     IShowTimesMapper returned_showtime = movies_bll.InsertShowTime(movie1, showtime1);
 }
 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 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);
        }
        //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);
        }