Exemplo n.º 1
0
        public static Shows[] WatchHistory(string username)
        {
            Shows[] shows = new Shows[10];

            return(shows);
        }
Exemplo n.º 2
0
        public static List <Shows> getShows()
        {
            List <Shows> allShows = new List <Shows>();

            //Get Total number of shows in database
            SqlParameter param = new SqlParameter("@maxId", System.Data.SqlDbType.Int);

            param.Direction = System.Data.ParameterDirection.Output;
            using (SqlConnection con = new SqlConnection(CRUD.connectionString))
            {
                SqlCommand cmd = new SqlCommand("ShowCount", con);
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.Parameters.Add(param);
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
            }
            //Create List for all shows
            for (int i = 1; i <= (int)param.Value; i++)
            {
                Shows s = new Shows();

                //Check if show exist for index
                SqlParameter returnParam = new SqlParameter("@return", System.Data.SqlDbType.Int);
                returnParam.Direction = System.Data.ParameterDirection.Output;
                using (SqlConnection con = new SqlConnection(CRUD.connectionString))
                {
                    SqlCommand cmd = new SqlCommand("ShowExistByID", con);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;
                    cmd.Parameters.Add("@idInput", System.Data.SqlDbType.Int).Value = i;
                    cmd.Parameters.Add(returnParam);
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                }

                //Insert into list
                if (!Convert.IsDBNull(returnParam.Value))
                {
                    SqlParameter showTypeParam = new SqlParameter("@showType", System.Data.SqlDbType.VarChar, 10);
                    SqlParameter movieIDParam  = new SqlParameter("@movieId", System.Data.SqlDbType.Int);
                    SqlParameter TVShowIDParam = new SqlParameter("@TVShowID", System.Data.SqlDbType.Int);
                    SqlParameter airDateParam  = new SqlParameter("@airDate", System.Data.SqlDbType.Date);

                    showTypeParam.Direction = System.Data.ParameterDirection.Output;
                    movieIDParam.Direction  = System.Data.ParameterDirection.Output;
                    TVShowIDParam.Direction = System.Data.ParameterDirection.Output;
                    airDateParam.Direction  = System.Data.ParameterDirection.Output;

                    using (SqlConnection con = new SqlConnection(CRUD.connectionString))
                    {
                        SqlCommand cmd = new SqlCommand("GetShowByID", con);
                        cmd.CommandType = System.Data.CommandType.StoredProcedure;
                        cmd.Parameters.Add("@idInput", System.Data.SqlDbType.Int).Value = i;

                        cmd.Parameters.Add(showTypeParam);
                        cmd.Parameters.Add(movieIDParam);
                        cmd.Parameters.Add(TVShowIDParam);
                        cmd.Parameters.Add(airDateParam);

                        con.Open();
                        cmd.ExecuteNonQuery();
                        con.Close();
                    }
                    s.showId   = i.ToString();
                    s.showType = (string)showTypeParam.Value;
                    s.movieId  = movieIDParam.Value.ToString();
                    s.TVShowId = TVShowIDParam.Value.ToString();
                    s.AirDate  = airDateParam.Value.ToString();
                    var spaceIndex = s.AirDate.IndexOf(" ");
                    s.AirDate = s.AirDate.Remove(spaceIndex);
                    allShows.Add(s);
                }
            }

            return(allShows);
        }