//GET ID
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.AddHeader("Content-Type", "application/json");
            try
            {
                if (int.TryParse(Request.QueryString["id"], out int id))
                {
                    var ConnectionString = System.Configuration.ConfigurationManager.
    ConnectionStrings["connection"].ConnectionString;
                    Commands cmd = new Commands(ConnectionString);
                    LibraryShared.Watch watch = cmd.GetWatch(id);
                    string json = JsonConvert.SerializeObject(watch, Formatting.Indented);
                    Response.Write(json);

                }
                else
                {
                    Response.StatusCode = 422;
                    string json = JsonConvert.SerializeObject("Parse int error.");
                    Response.Write(json);

                }
            }
            catch (ArgumentNullException)
            {
                Response.StatusCode = 422;
                string json = JsonConvert.SerializeObject("Does not exists record with ID requested.");
                Response.Write(json);
            }
            catch (Exception ex)
            {
                Response.StatusCode = 422;
                string json = JsonConvert.SerializeObject($"Error: {ex.Message}.");
                Response.Write(json);
            }


        }
Exemple #2
0
        public Watch GetWatch(int idWatch)
        {
            Watch watch = new Watch();

            System.Data.SqlClient.SqlCommand CommandSelect1 = new System.Data.SqlClient.SqlCommand();
            CommandSelect1.Connection  = Connection.Connect();
            CommandSelect1.CommandText = "SELECT [Title] ,[TitleOriginal] ,[Duration] ,[Synopsis] ,[IDTheMovieDB] ,[IDIMdb] ,[PosterPicture] ,[BackdropPicture] ,[Date] ,[IsMovie] FROM [dbo].[Watch] " +
                                         "WHERE idWatch = " + idWatch.ToString();
            using (System.Data.SqlClient.SqlDataReader reader = CommandSelect1.ExecuteReader())
            {
                if (reader.Read())
                {
                    watch.Title           = reader["Title"].ToString();
                    watch.TitleOriginal   = reader["TitleOriginal"].ToString();
                    watch.Duration        = reader["Duration"].ToString();
                    watch.Synopsis        = reader["Synopsis"].ToString();
                    watch.IDTheMovieDB    = Convert.ToInt32(reader["IDTheMovieDB"]);
                    watch.IDIMDb          = reader["IDIMdb"].ToString();
                    watch.PosterPicture   = reader["PosterPicture"].ToString();
                    watch.BackdropPicture = reader["BackdropPicture"].ToString();
                    watch.Date            = reader["Date"].ToString();
                    watch.Type            = GetType((bool)reader["IsMovie"]);
                }
                else
                {
                    throw new ArgumentNullException("Not found.");
                }
            }
            Connection.Disconnect();

            System.Data.SqlClient.SqlCommand CommandSelect2 = new System.Data.SqlClient.SqlCommand();
            CommandSelect2.Connection  = Connection.Connect();
            CommandSelect2.CommandText = "SELECT [Genre] FROM [dbo].[Genre]" +
                                         "WHERE idWatch = " + idWatch.ToString();
            var listGenre = new System.Collections.Generic.List <string>();

            using (System.Data.SqlClient.SqlDataReader reader = CommandSelect2.ExecuteReader())
            {
                while (reader.Read())
                {
                    listGenre.Add(reader["Genre"].ToString());
                }
            }
            watch.Genres = listGenre.ToArray();
            Connection.Disconnect();

            System.Data.SqlClient.SqlCommand CommandSelect3 = new System.Data.SqlClient.SqlCommand();
            CommandSelect3.Connection  = Connection.Connect();
            CommandSelect3.CommandText = "SELECT [Download].[Quality] ,[Download].[Audio] ,[Download].[Format] ,[Download].[Size] ,[Download].[SeasonTV] ,[Download].[EpisodeTV] ,[Download].[DownloadText] FROM [dbo].[Watch_Download] " +
                                         "INNER JOIN [Download] ON [Watch_Download].[idDownload] = [Download].[idDownload] " +
                                         "WHERE idWatch = " + idWatch.ToString();
            using (System.Data.SqlClient.SqlDataReader reader = CommandSelect3.ExecuteReader())
            {
                while (reader.Read())
                {
                    DownloadData downloadData = new DownloadData();
                    downloadData.Audio        = reader["Audio"].ToString();
                    downloadData.Format       = reader["Format"].ToString();
                    downloadData.Size         = reader["Size"].ToString();
                    downloadData.SeasonTV     = (int)reader["SeasonTV"];
                    downloadData.EpisodeTV    = reader["EpisodeTV"].ToString();
                    downloadData.DownloadText = reader["DownloadText"].ToString();
                    watch.Downloads.Add(downloadData);
                }
            }
            Connection.Disconnect();

            return(watch);
        }