Example #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(CommentM model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into CommentTab(");
            strSql.Append("description,CommDate,SendName,LinkMode,LinkName)");
            strSql.Append(" values (");
            strSql.Append("@description,getdate(),@SendName,@LinkMode,@LinkName)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@description", SqlDbType.NVarChar, 1500),
                //new SqlParameter("@CommDate", SqlDbType.DateTime),
                new SqlParameter("@SendName",    SqlDbType.VarChar,    50),
                new SqlParameter("@LinkMode",    SqlDbType.VarChar,    50),
                new SqlParameter("@LinkName",    SqlDbType.VarChar, 50)
            };
            parameters[0].Value = model.description;
            //parameters[1].Value = model.CommDate;
            parameters[1].Value = model.SendName;
            parameters[2].Value = model.LinkMode;
            parameters[3].Value = model.LinkName;
            object obj = DBHelper.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Example #2
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(CommentM model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update CommentTab set ");
            strSql.Append("description=@description,");
            strSql.Append("LinkName=@LinkName,");
            strSql.Append("SendName=@SendName,");
            strSql.Append("LinkMode=@LinkMode");
            strSql.Append(" where CommentId=@CommentId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CommentId",   SqlDbType.Int,         4),
                new SqlParameter("@description", SqlDbType.NVarChar, 1500),
                new SqlParameter("@LinkName",    SqlDbType.VarChar,    50),
                new SqlParameter("@SendName",    SqlDbType.VarChar,    50),
                new SqlParameter("@LinkMode",    SqlDbType.VarChar, 50)
            };
            parameters[0].Value = model.CommentId;
            parameters[1].Value = model.description;
            parameters[2].Value = model.CommDate;
            parameters[3].Value = model.SendName;
            parameters[4].Value = model.LinkMode;

            int rows = DBHelper.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #3
0
        /// <summary>
        /// 获得数据列表
        /// </summary>
        public List <CommentM> DataTableToList(DataTable dt)
        {
            List <CommentM> modelList = new List <CommentM>();
            int             rowsCount = dt.Rows.Count;

            if (rowsCount > 0)
            {
                CommentM model;
                for (int n = 0; n < rowsCount; n++)
                {
                    model = new CommentM();
                    if (dt.Rows[n]["CommentId"].ToString() != "")
                    {
                        model.CommentId = int.Parse(dt.Rows[n]["CommentId"].ToString());
                    }
                    model.description = dt.Rows[n]["description"].ToString();
                    if (dt.Rows[n]["CommDate"].ToString() != "")
                    {
                        model.CommDate = DateTime.Parse(dt.Rows[n]["CommDate"].ToString());
                    }
                    model.SendName = dt.Rows[n]["SendName"].ToString();
                    model.LinkMode = dt.Rows[n]["LinkMode"].ToString();
                    modelList.Add(model);
                }
            }
            return(modelList);
        }
Example #4
0
        public IHttpActionResult PostComment([FromBody] CommentM comment)
        {
            IDentifier.currentID += 1;
            var commentEntry = new Comment(Organization.GetInstance().FindUserByID(comment.AuthorId), comment.CreationTime, new Rating(0, 0), IDentifier.currentID, comment.Body, comment.CommentingEntryId);

            commentService.PostEntry(commentEntry);


            return(Ok("I did it"));
        }
Example #5
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public CommentM GetModel(int CommentId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select  top 1 CommentId,description,LinkName,CommDate,SendName,LinkMode from CommentTab ");
            strSql.Append(" where CommentId=@CommentId");
            SqlParameter[] parameters =
            {
                new SqlParameter("@CommentId", SqlDbType.Int, 4)
            };
            parameters[0].Value = CommentId;

            CommentM model = new CommentM();
            DataSet  ds    = DBHelper.Query(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["CommentId"].ToString() != "")
                {
                    model.CommentId = int.Parse(ds.Tables[0].Rows[0]["CommentId"].ToString());
                }
                model.description = ds.Tables[0].Rows[0]["description"].ToString();
                if (ds.Tables[0].Rows[0]["CommDate"].ToString() != "")
                {
                    model.CommDate = DateTime.Parse(ds.Tables[0].Rows[0]["CommDate"].ToString());
                }
                model.SendName = ds.Tables[0].Rows[0]["SendName"].ToString();
                model.LinkMode = ds.Tables[0].Rows[0]["LinkMode"].ToString();
                model.LinkName = ds.Tables[0].Rows[0]["LinkName"].ToString();
                return(model);
            }
            else
            {
                return(null);
            }
        }
Example #6
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(CommentM model)
 {
     return(dal.Update(model));
 }
Example #7
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(CommentM model)
 {
     return(dal.Add(model));
 }