/// <summary>
        /// Carrega o artigo pelo id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List <ArticleActionObservation> LoadAllFrom(ArticleAction na)
        {
            List <ArticleActionObservation> lst = new List <ArticleActionObservation>();

            SqlCommand sel = new SqlCommand();

            sel.CommandText = "SELECT userid, included, observation FROM " + Base.conf.prefix + "[newsarticleactionobservation] WHERE id=@id ORDER BY included";
            sel.Parameters.Add(new SqlParameter("@id", na.id));

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

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

                ArticleActionObservation ngo = new ArticleActionObservation(na);

                ngo.useridInt      = rdr.GetString(0);
                ngo.includedInt    = rdr.GetDateTime(1);
                ngo.observationInt = rdr.GetString(2);

                lst.Add(ngo);
            }

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

            return(lst);
        }
Beispiel #2
0
        /// <summary>
        /// Salva a ticket
        /// </summary>
        /// <returns></returns>
        public bool Save()
        {
            bool res = false;

            SqlCommand sel = new SqlCommand();

            sel.CommandText = "SELECT id FROM " + Base.conf.prefix + "[newsarticleaction] 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 + "[newsarticleaction] (id, articleid, userid, type, observation, date, show, billablewords, text) VALUES (@id, @articleid, @userid, @type, @observation, @date, @show, @billablewords, @text)";
                ins.Parameters.Add(new SqlParameter("@id", id));

                ins.Parameters.Add(new SqlParameter("@articleid", article.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.Parameters.Add(new SqlParameter("@billablewords", billablewordsInt));
                ins.Parameters.Add(new SqlParameter("@text", textInt));

                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 + "[newsarticleaction] SET articleid=@articleid, userid=@userid, type=@type, observation=@observation, date=@date, show=@show, billablewords=@billablewords, text=@text WHERE id=@id";

                upd.Parameters.Add(new SqlParameter("@articleid", article.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("@billablewords", billablewordsInt));
                upd.Parameters.Add(new SqlParameter("@text", textInt));

                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)
                {
                    ArticleActionGrant.SaveAll(this, grants);
                }

                if (observationsInt != null)
                {
                    ArticleActionObservation.SaveAll(this, observations);
                }
            }

            return(res);
        }