Ejemplo n.º 1
0
        /// <summary>
        /// Carrega o artigo pelo id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static List <ArticleActionGrant> LoadAllFrom(ArticleAction na)
        {
            List <ArticleActionGrant> lst = new List <ArticleActionGrant>();

            SqlCommand sel = new SqlCommand();

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

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

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

                ArticleActionGrant nga = new ArticleActionGrant(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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adiciona um grant pelo usuário
        /// </summary>
        /// <param name="awardId"></param>
        /// <param name="userId"></param>
        public void AddGrant(string awardId, string userId)
        {
            for (int i = 0; i < grants.Count; i++)
            {
                if (grants[i].awardId == awardId)
                {
                    return;
                }
            }

            ArticleActionGrant tag = new ArticleActionGrant(this);

            tag.awardId     = awardId;
            tag.grantedById = userId;
            tag.granted     = DateTime.Now;

            grants.Add(tag);

            profile.AddAward(awardId);
        }
Ejemplo n.º 3
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);
        }