Пример #1
0
        /// <summary>
        /// Carrega o artigo pelo id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List <VideoActionGrant> LoadAllFrom(VideoAction na)
        {
            List <VideoActionGrant> lst = new List <VideoActionGrant>();

            SqlCommand sel = new SqlCommand();

            sel.CommandText = "SELECT awardid, grantedby, granted FROM " + Base.conf.prefix + "[newsvideoactiongrant] WHERE id=@id ORDER BY granted";
            sel.Parameters.Add(new SqlParameter("@id", na.id));

            sel.Connection = Base.conf.Open();
            SqlDataReader rdr = sel.ExecuteReader();

            if (rdr.Read())
            {
                // Pega as informações

                VideoActionGrant nga = new VideoActionGrant(na);

                nga.awardidInt  = rdr.GetString(0);
                nga.grantedById = rdr.GetString(1);
                nga.granted     = rdr.GetDateTime(2);

                lst.Add(nga);
            }

            rdr.Close();
            sel.Connection.Close();

            return(lst);
        }
Пример #2
0
        /// <summary>
        /// Salva a ação
        /// </summary>
        /// <returns></returns>
        public bool Save()
        {
            bool res = false;

            SqlCommand sel = new SqlCommand();

            sel.CommandText = "SELECT id FROM " + Base.conf.prefix + "[newsvideoaction] WHERE id=@id";
            sel.Parameters.Add(new SqlParameter("@id", id));

            sel.Connection = Base.conf.Open();
            SqlDataReader rdr = sel.ExecuteReader();

            if (!rdr.Read())
            {
                rdr.Close();
                sel.Connection.Close();

                SqlCommand ins = new SqlCommand();
                ins.CommandText = "INSERT INTO " + Base.conf.prefix + "[newsvideoaction] (id, videoid, userid, type, observation, date, show) VALUES (@id, @videoid, @userid, @type, @observation, @date, @show)";
                ins.Parameters.Add(new SqlParameter("@id", id));

                ins.Parameters.Add(new SqlParameter("@videoid", video.id));
                ins.Parameters.Add(new SqlParameter("@userid", useridInt));
                ins.Parameters.Add(new SqlParameter("@type", typeInt));
                ins.Parameters.Add(new SqlParameter("@observation", observationInt));
                ins.Parameters.Add(new SqlParameter("@date", dateInt));
                ins.Parameters.Add(new SqlParameter("@show", showInt));

                ins.Connection = Base.conf.Open();
                ins.ExecuteNonQuery();
                ins.Connection.Close();

                res             = true;
                dbassignedidInt = true;
            }
            else
            {
                rdr.Close();
                sel.Connection.Close();

                SqlCommand upd = new SqlCommand();
                upd.CommandText = "UPDATE " + Base.conf.prefix + "[newsvideoaction] SET videoid=@videoid, userid=@userid, type=@type, observation=@observation, date=@date, show=@show WHERE id=@id";

                upd.Parameters.Add(new SqlParameter("@videoid", video.id));
                upd.Parameters.Add(new SqlParameter("@userid", useridInt));
                upd.Parameters.Add(new SqlParameter("@type", typeInt));
                upd.Parameters.Add(new SqlParameter("@observation", observationInt));
                upd.Parameters.Add(new SqlParameter("@date", dateInt));
                upd.Parameters.Add(new SqlParameter("@show", showInt));

                upd.Parameters.Add(new SqlParameter("@id", id));

                upd.Connection = Base.conf.Open();
                upd.ExecuteNonQuery();
                upd.Connection.Close();

                res             = true;
                dbassignedidInt = true;
            }

            if (res)
            {
                if (grantsInt != null)
                {
                    VideoActionGrant.SaveAll(this, grants);
                }
            }

            return(res);
        }