public static int Save(int movieId, Movie movieToSave)
 {
     int returnedMovieId = 0;
     if (movieId > 0)
     {
         //Call DAL to save
         MovieDAL.SaveMovieYearReleasedRating(movieToSave.MovieId, returnedMovieId, movieToSave);
         return MovieDAL.Save(movieId, movieToSave);
     }
     else
     {
         returnedMovieId = MovieDAL.Save(movieId, movieToSave);
         return MovieDAL.SaveMovieYearReleasedRating(returnedMovieId, returnedMovieId, movieToSave);
     }
 }
        public static int Save(int movieId, int movieIdForSaving, Movie movieToSave)
        {
            MovieExecuteTypeEnums queryId = MovieExecuteTypeEnums.InsertItem;
            int result = 0;

            if (movieToSave.MovieId > 0)
            {
                queryId = MovieExecuteTypeEnums.UpdateItem;
            }

            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_ExecuteMovieRatingCountryYearFormat", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;

                    myCommand.Parameters.AddWithValue("@QueryId", queryId);
                    myCommand.Parameters.AddWithValue("@MovieId", movieIdForSaving);

                    if (movieToSave.RatingName != null)
                    {
                        myCommand.Parameters.AddWithValue("@RatingId", movieToSave.RatingId);
                    }
                    if (movieToSave.YearReleased != null)
                    {
                        myCommand.Parameters.AddWithValue("@YearReleased", movieToSave.YearReleased);
                    }

                    //add return output parameter to command object
                    myCommand.Parameters.Add(HelperDAL.GetReturnParameterInt("ReturnValue"));

                    myConnection.Open();
                    myCommand.ExecuteNonQuery();

                    //Get return value from stored procedure and return Id
                    result = (int)myCommand.Parameters["@ReturnValue"].Value;
                }
                myConnection.Close();
            }
            return result;
        }
        /// <Summary Fill Data Record>
        /// Initializes a new instance of the Game class and fills it with the data from the IDataRecord
        /// </summary>
        /// <param name="myDataRecord"></param>
        /// <returns></returns>
        private static Movie FillDataRecord(IDataRecord myDataRecord)
        {
            Movie myMovieObject = new Movie();

            myMovieObject.MovieId = myDataRecord.GetInt32(myDataRecord.GetOrdinal("MovieId"));

            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("MovieName")))
            {
                myMovieObject.MovieTitle = myDataRecord.GetString(myDataRecord.GetOrdinal("MovieName"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("YearReleased")))
            {
                myMovieObject.YearReleased = myDataRecord.GetInt32(myDataRecord.GetOrdinal("YearReleased"));
            }
            if (!myDataRecord.IsDBNull(myDataRecord.GetOrdinal("RatingsName")))
            {
                myMovieObject.RatingName = myDataRecord.GetString(myDataRecord.GetOrdinal("RatingsName"));
            }

            return myMovieObject;
        }
 public static int Save(int movieId, int movieIdForSaving, Movie movieToSave)
 {
     //Call DAL to save Rating and Year Released
     return RatingDAL.Save(movieId, movieIdForSaving, movieToSave);
 }