Ejemplo n.º 1
0
        public bool DeleteBlog(string id)
        {
            string sql = "delete from blog Where Id=@Id;delete from comment where blogid=@blogid";

            List <SqlParameter> parameters = new List <SqlParameter>();

            SqlParameter p1 = new SqlParameter();

            p1.ParameterName = "@Id";

            SqlParameter p2 = new SqlParameter();

            p2.ParameterName = "@blogid";

            if (string.IsNullOrEmpty(id))
            {
                return(false);
            }
            else
            {
                Guid guid = new Guid(id);
                p1.Value = guid;
                p2.Value = guid;
            }
            parameters.Add(p1);
            parameters.Add(p2);

            return(DataAccessBase.ExecuteNonQuery(sql, DataAccessBase.CONNECTION_STRING, parameters.ToArray()));
        }
Ejemplo n.º 2
0
        public bool SaveComment(string comment, string blogId)
        {
            bool success = false;

            string sql = string.Empty;

            //if (string.IsNullOrEmpty(id))
            //{
            sql = "insert into Comment(CommentId, BlogId, Comment, CreatedTime, UpdatedTime) values (newid(), @BlogId, @Commnet, getdate(), getdate())";
            //}
            //else
            //{
            //    sql = "Update blog set Title=@Title, Content=@Content, UpdatedTime=@UpdatedTime where Id=@Id";
            //}

            List <SqlParameter> parameters = new List <SqlParameter>();

            SqlParameter p1 = new SqlParameter();

            p1.ParameterName = "@BlogId";
            //if (string.IsNullOrEmpty(id))
            //{
            //    p1.Value = Guid.NewGuid();
            //}
            //else
            //{
            Guid guid = new Guid(blogId);

            p1.Value = guid;
            //}
            parameters.Add(p1);

            SqlParameter p2 = new SqlParameter();

            p2.ParameterName = "@Commnet";
            p2.Value         = comment;
            parameters.Add(p2);

            try
            {
                success = DataAccessBase.ExecuteNonQuery(sql, DataAccessBase.CONNECTION_STRING, parameters.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(success);
        }
Ejemplo n.º 3
0
        public bool SaveBlog(string id, string title, string content)
        {
            bool success = false;

            string sql = string.Empty;

            if (string.IsNullOrEmpty(id))
            {
                sql = "insert into blog(Id,Title,Content,CreatedTime,UpdatedTime) values (@Id,@Title,@Content,@CreatedTime,@UpdatedTime)";
            }
            else
            {
                sql = "Update blog set Title=@Title, Content=@Content, UpdatedTime=@UpdatedTime where Id=@Id";
            }

            List <SqlParameter> parameters = new List <SqlParameter>();

            SqlParameter p1 = new SqlParameter();

            p1.ParameterName = "@Id";
            if (string.IsNullOrEmpty(id))
            {
                p1.Value = Guid.NewGuid();
            }
            else
            {
                Guid guid = new Guid(id);
                p1.Value = guid;
            }
            parameters.Add(p1);

            SqlParameter p2 = new SqlParameter();

            p2.ParameterName = "@Title";
            p2.Value         = title;
            parameters.Add(p2);

            SqlParameter p3 = new SqlParameter();

            p3.ParameterName = "@Content";
            p3.Value         = content;
            parameters.Add(p3);

            if (string.IsNullOrEmpty(id))
            {
                SqlParameter p4 = new SqlParameter();

                p4.ParameterName = "@CreatedTime";
                p4.Value         = DateTime.Now;

                parameters.Add(p4);
            }

            SqlParameter p5 = new SqlParameter();

            p5.ParameterName = "@UpdatedTime";
            p5.Value         = DateTime.Now;
            parameters.Add(p5);

            try
            {
                success = DataAccessBase.ExecuteNonQuery(sql, DataAccessBase.CONNECTION_STRING, parameters.ToArray());
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(success);
        }