Exemplo n.º 1
0
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Insert(BlogPostInfo model)
        {
            string strSQL = "INSERT INTO BlogPosts(UserId,Title,Content,ViewCount,CreateDateTime,SystemCategoryId,Tags,UserName,SystemCategoryName) VALUES(@UserId,@Title,@Content,0,GETDATE(),@SystemCategoryId,@Tags,@UserName,@SystemCategoryName);SELECT @@IDENTITY;";

            SqlParameter[] parms =
            {
                new SqlParameter("Id",                 SqlDbType.Int),
                new SqlParameter("UserId",             SqlDbType.Int),
                new SqlParameter("Title",              SqlDbType.NVarChar),
                new SqlParameter("Content",            SqlDbType.NVarChar),
                new SqlParameter("SystemCategoryId",   SqlDbType.Int),
                new SqlParameter("Tags",               SqlDbType.NVarChar),
                new SqlParameter("UserName",           SqlDbType.NVarChar),
                new SqlParameter("SystemCategoryName", SqlDbType.NVarChar),
            };
            parms[0].Value = model.Id;
            parms[1].Value = model.UserId;
            parms[2].Value = string.IsNullOrEmpty(model.Title) ? string.Empty : model.Title;
            parms[3].Value = string.IsNullOrEmpty(model.Content) ? string.Empty : model.Content;
            parms[4].Value = model.SystemCategoryId;
            parms[5].Value = string.IsNullOrEmpty(model.Tags) ? string.Empty : model.Tags;
            parms[6].Value = model.UserName;
            parms[7].Value = model.SystemCategoryName;

            return(Convert.ToInt32(SQLPlus.ExecuteScalar(CommandType.Text, strSQL, parms)));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获得没有分页的博客列表
        /// 默认10条
        /// </summary>
        /// <param name="userId">0</param>
        /// <param name="topCount">默认10条</param>
        /// <returns></returns>
        public static IList <BlogPostInfo> ListWithoutPage(int userId, int topCount = 10)
        {
            IList <BlogPostInfo> list  = new List <BlogPostInfo>();
            BlogPostInfo         model = null;
            string strSQL = "SELECT TOP(@TopCount) * FROM BlogPosts WITH(NOLOCK) WHERE UserId = @UserId AND IsDeleted = 0 ORDER BY CreateDateTime DESC";

            SqlParameter[] parms =
            {
                new SqlParameter("TopCount", SqlDbType.Int),
                new SqlParameter("UserId",   SqlDbType.Int),
            };
            parms[0].Value = topCount;
            parms[1].Value = userId;
            DataTable dt = SQLPlus.ExecuteDataTable(CommandType.Text, strSQL, parms);

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    model = GetByDataRow(dr);
                    if (model != null)
                    {
                        list.Add(model);
                    }
                }
            }
            return(list);
        }
Exemplo n.º 3
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static BlogPostInfo Update(BlogPostInfo model)
 {
     if (model.Id == 0)
     {
         int id = BlogPostManage.Insert(model);
         model.Id = id;
     }
     else
     {
         BlogPostManage.Update(model);
     }
     return(model);
 }
Exemplo n.º 4
0
        public ActionResult Edit(BlogPostInfo oldModel, FormCollection fc)
        {
            bool   error    = false;
            bool   isAdd    = oldModel.Id == 0;
            int    userId   = PlantEngContext.Current.UserId;
            string userName = PlantEngContext.Current.UserName;

            if (string.IsNullOrEmpty(oldModel.Title))
            {
                error = true;
                ModelState.AddModelError("TITLEEMPTY", "标题不能为空");
            }
            if (string.IsNullOrEmpty(oldModel.Content))
            {
                error = true;
                ModelState.AddModelError("CONTENTEMPTY", "内容不能为空");
            }
            //系统分类
            oldModel.SystemCategoryId = Utils.StrToInt(fc["ddlSystemCategory"], 0);
            if (oldModel.SystemCategoryId == 0)
            {
                error = true;
                ModelState.AddModelError("SYSTEMCATERROR", "请选择系统分类");
            }
            if (!error && ModelState.IsValid)
            {
                oldModel.UserId   = userId;
                oldModel.UserName = userName;

                //获得系统分类名称
                oldModel.SystemCategoryName = PlantEng.Services.Category.TechService.GetById(oldModel.SystemCategoryId).Name;


                BlogPostService.Update(oldModel);
                if (isAdd)
                {
                    ViewBag.Msg = "添加成功,继续[<a href=\"/accounts/edit\">添加</a>]或[<a href=\"/accounts/blog/\">返回</a>]";
                }
                else
                {
                    ViewBag.Msg = "更新成功,<a href=\"/accounts/blog/\">返回</a>";
                }
            }
            return(View(oldModel));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 博客列表
        /// </summary>
        /// <param name="searchSetting"></param>
        /// <returns></returns>
        public static IPageOfList <BlogPostInfo> List(BlogSearchSetting searchSetting)
        {
            FastPaging fp = new FastPaging();

            fp.OverOrderBy = " BP.CreateDateTime DESC";
            fp.PageIndex   = searchSetting.PageIndex;
            fp.PageSize    = searchSetting.PageSize;
            fp.QueryFields = "*";
            fp.TableName   = "BlogPosts";
            fp.PrimaryKey  = "Id";
            fp.TableReName = "BP";
            fp.WithOptions = " WITH(NOLOCK)";
            StringBuilder sbCondition = new StringBuilder();

            sbCondition.Append(" IsDeleted = 0 ");
            if (searchSetting.UserId > 0)
            {
                sbCondition.AppendFormat("  AND UserId = {0}", searchSetting.UserId);
            }
            if (searchSetting.SystemCategoryId > 0)
            {
                sbCondition.AppendFormat("  AND SystemCategoryId = {0}", searchSetting.SystemCategoryId);
            }
            fp.Condition = sbCondition.ToString();

            IList <BlogPostInfo> list  = new List <BlogPostInfo>();
            BlogPostInfo         model = null;
            DataTable            dt    = SQLPlus.ExecuteDataTable(CommandType.Text, fp.Build2005());

            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    model = GetByDataRow(dr);
                    if (model != null)
                    {
                        list.Add(model);
                    }
                }
            }
            int count = Convert.ToInt32(SQLPlus.ExecuteScalar(CommandType.Text, fp.BuildCountSQL()));

            return(new PageOfList <BlogPostInfo>(list, searchSetting.PageIndex, searchSetting.PageSize, count));
        }
Exemplo n.º 6
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static int Update(BlogPostInfo model)
        {
            string strSQL = "UPDATE BlogPosts SET Title = @Title,Content = @Content,SystemCategoryId = @SystemCategoryId,Tags = @Tags,SystemCategoryName = @SystemCategoryName WHERE Id = @Id AND UserId = @UserId";

            SqlParameter[] parms =
            {
                new SqlParameter("Id",                 SqlDbType.Int),
                new SqlParameter("UserId",             SqlDbType.Int),
                new SqlParameter("Title",              SqlDbType.NVarChar),
                new SqlParameter("Content",            SqlDbType.NVarChar),
                new SqlParameter("SystemCategoryId",   SqlDbType.Int),
                new SqlParameter("Tags",               SqlDbType.NVarChar),
                new SqlParameter("SystemCategoryName", SqlDbType.NVarChar),
            };
            parms[0].Value = model.Id;
            parms[1].Value = model.UserId;
            parms[2].Value = string.IsNullOrEmpty(model.Title) ? string.Empty : model.Title;
            parms[3].Value = string.IsNullOrEmpty(model.Content) ? string.Empty : model.Content;
            parms[4].Value = model.SystemCategoryId;
            parms[5].Value = string.IsNullOrEmpty(model.Tags) ? string.Empty : model.Tags;
            parms[6].Value = model.SystemCategoryName;

            return(SQLPlus.ExecuteNonQuery(CommandType.Text, strSQL, parms));
        }