public static MovieActorComboDO ComboPOtoDO(MovieActorCombo from)
        {
            MovieActorComboDO to = new MovieActorComboDO();

            to.ActorId = from.ActorId;
            to.MovieId = from.MovieId;

            return(to);
        }
Beispiel #2
0
        //Adding an actor to a movie method
        public void AddActorToMovie(MovieActorComboDO comboDO)
        {
            //Setting connection and command to null
            SqlConnection connectionToSql = null;
            SqlCommand    storedProcedure = null;

            try
            {
                //Instantiating the connection
                connectionToSql = new SqlConnection(_ConnectionString);
                //Instantiating my sqlcommand to get my procedure
                storedProcedure             = new SqlCommand("ADD_ACTOR_TO_MOVIE", connectionToSql);
                storedProcedure.CommandType = CommandType.StoredProcedure;

                //Throwing the movie and actorID into the procedure to get the details
                storedProcedure.Parameters.AddWithValue("@MovieID", comboDO.MovieId);
                storedProcedure.Parameters.AddWithValue("@ActorID", comboDO.ActorId);

                //Open connection
                connectionToSql.Open();

                //Not getting anything back
                storedProcedure.ExecuteNonQuery();
            }
            catch (Exception exception)
            {
                //Log and throw exception if there's an error
                _Logger.Log("Fatal", exception.Source, exception.TargetSite.ToString(), exception.Message, exception.StackTrace);

                throw exception;
            }
            finally
            {
                //If there's a connection, close and dispose
                if (connectionToSql != null)
                {
                    connectionToSql.Close();
                    connectionToSql.Dispose();
                }
                else
                {
                }
            }
        }
        public ActionResult AddActorToMovie(MovieActorCombo combo)
        {
            //Setting the response to null
            ActionResult response = null;

            if (ModelState.IsValid)
            {
                try
                {
                    //Setting the movie/actor combo to DO from PO
                    MovieActorComboDO comboDO = Mapping.Mapper.ComboPOtoDO(combo);
                    //Passing in the DO combo to the add actor to movie method
                    _movieDAO.AddActorToMovie(comboDO);
                }
                catch (Exception exception)
                {
                    //Logs if there's an issue
                    _Logger.Log("Fatal", exception.Source, exception.TargetSite.ToString(), exception.Message, exception.StackTrace);

                    //Setting view, to go to the actual view that ties an actor to a movie.
                    response = View(combo);
                }
                finally
                {
                    //Setting response to view all the movies
                    response = RedirectToAction("ViewAllMovies", "Movie");
                }
            }
            else
            {
                //Setting response to view the movie you're currently on
                response = View(combo);
            }
            //Show whichever response happened
            return(response);
        }