示例#1
0
        public int AddTitle(TitleList title)
        {
            try
            {
                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand("spAddTitle", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    cmd.Parameters.AddWithValue("@Name", title.Name);
                    cmd.Parameters.AddWithValue("@Director", title.Director);
                    cmd.Parameters.AddWithValue("@Description", title.Description);
                    cmd.Parameters.AddWithValue("@IMDBU", title.IMDBU);
                    cmd.Parameters.AddWithValue("@IMDBR", title.IMDBR);
                    cmd.Parameters.AddWithValue("@Status", title.Status);
                    cmd.Parameters.AddWithValue("@Score", title.Score);

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
                return(1);
            }
            catch
            {
                throw;
            }
        }
示例#2
0
        public TitleList GetTitleData(int id)
        {
            try
            {
                TitleList elem = new TitleList();

                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    string     sqlQuery = "SELECT * FROM TitlesList WHERE Id= " + id;
                    SqlCommand cmd      = new SqlCommand(sqlQuery, con);

                    con.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        elem.ID          = Convert.ToInt32(rdr["Id"]);
                        elem.Name        = rdr["Name"].ToString();
                        elem.Director    = rdr["Director"].ToString();
                        elem.Description = rdr["Description"].ToString();
                        elem.Status      = Convert.ToInt32(rdr["Status"]);
                        elem.Score       = Convert.ToInt32(rdr["Score"]);
                        elem.IMDBU       = rdr["IMDBU"].ToString();
                        elem.IMDBR       = rdr["IMDBR"].ToString();
                    }
                }
                return(elem);
            }
            catch
            {
                throw;
            }
        }
示例#3
0
        //To View all titles details
        public IEnumerable <TitleList> GetAllTitles()
        {
            try
            {
                List <TitleList> titles = new List <TitleList>();

                using (SqlConnection con = new SqlConnection(connectionString))
                {
                    SqlCommand cmd = new SqlCommand("spGetAllTitles", con);
                    cmd.CommandType = CommandType.StoredProcedure;

                    con.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        TitleList elem = new TitleList();

                        elem.ID          = Convert.ToInt32(rdr["Id"]);
                        elem.Name        = rdr["Name"].ToString();
                        elem.Director    = rdr["Director"].ToString();
                        elem.Description = rdr["Description"].ToString();
                        elem.Status      = Convert.ToInt32(rdr["Status"]);
                        elem.Score       = Convert.ToInt32(rdr["Score"]);
                        elem.IMDBU       = rdr["IMDBU"].ToString();
                        elem.IMDBR       = rdr["IMDBR"].ToString();

                        titles.Add(elem);
                    }
                    con.Close();
                }
                return(titles);
            }
            catch
            {
                throw;
            }
        }