Exemple #1
0
 public PostModel()
 {
     Tags = new List<TagInfo>();
     Next = new PostInfo();
     Previous = new PostInfo();
     RelatedPosts = new List<PostInfo>();
 }
Exemple #2
0
        /// <summary>
        /// 删除文章
        /// </summary>
        /// <param name="post"></param>
        public virtual int Delete(PostInfo post)
        {
            PostInfo oldPost = GetById(post.PostId);
            if (oldPost == null) throw new Exception("文章不存在");

            string cmdText = string.Format("delete from [{0}posts] where [PostId] = @PostId", ConfigHelper.Tableprefix);
            using(var conn = new DapperHelper().OpenConnection())
            {
               return conn.Execute(cmdText, new {PostId = post.PostId });
            }
        }
Exemple #3
0
        /// <summary>
        /// 检查别名是否重复
        /// </summary>
        /// <returns></returns>
        public virtual void CheckPageName(PostInfo post)
        {
            if (string.IsNullOrEmpty(post.PageName))
            {
                return;
            }
            while (true)
            {
                string cmdText = post.PostId == 0 ? string.Format("select count(1) from [{1}posts] where [pagename]='{0}'  ", post.PageName, ConfigHelper.Tableprefix) : string.Format("select count(1) from [{2}posts] where [pagename]='{0}'   and [postid]<>{1}", post.PageName, post.PostId, ConfigHelper.Tableprefix);

                using (var conn = new DapperHelper().OpenConnection())
                {
                    int r = conn.Query<int>(cmdText,null).First();

                    if (r == 0)
                    {
                        return;
                    }
                }
                post.PageName += "-2";
            }
        }
Exemple #4
0
 public PostModel()
 {
     Post = new PostInfo();
     CateSelectItem = new List<SelectListItem>();
     TagList = new List<TagInfo>();
 }
Exemple #5
0
        /// <summary>
        /// 更新文章
        /// </summary>
        /// <param name="post"></param>
        public virtual int Update(PostInfo post)
        {
            string cmdText = string.Format(@"update [{0}posts] set
                                       [CategoryId]=@CategoryId,
                                       [TitlePic]=@TitlePic,
                                       [Title]=@Title,
                                       [Summary]=@Summary,
                                       [PostContent]=@PostContent,
                                       [PageName]=@PageName,
                                       [UserId]=@UserId,
                                       [CommentStatus]=@CommentStatus,
                                       [CommentCount]=@CommentCount,
                                       [ViewCount]=@ViewCount,
                                       [Tag]=@Tag,
                                       [UrlFormat]=@UrlFormat,
                                       [Template]=@Template,
                                       [Recommend]=@Recommend,
                                       [Status]=@Status,
                                       [TopStatus]=@TopStatus,
                                       [HomeStatus]=@HomeStatus,
                                       [PostTime]=@PostTime,
                                       [UpdateTime]=@UpdateTime
                                   where [PostId]=@PostId", ConfigHelper.Tableprefix);

            using (var conn = new DapperHelper().OpenConnection())
            {
               return conn.Execute(cmdText, post);
            }
        }
Exemple #6
0
        /// <summary>
        /// 新增文章
        /// </summary>
        /// <param name="post"></param>
        /// <returns></returns>
        public virtual int Insert(PostInfo post)
        {
            CheckPageName(post);
            string cmdText = string.Format(@"insert into [{0}posts]
                                (
                               [CategoryId],[TitlePic],[Title],[Summary],[PostContent],[PageName],[UserId],[CommentStatus],[CommentCount],[ViewCount],[Tag],[UrlFormat],[Template],[Recommend],[Status],[TopStatus],[HomeStatus],[PostTime],[UpdateTime]
                                )
                                values
                                (
                                @CategoryId,@TitlePic,@Title,@Summary,@PostContent,@PageName,@UserId,@CommentStatus,@CommentCount,@ViewCount,@Tag,@UrlFormat,@Template,@Recommend,@Status,@TopStatus,@HomeStatus,@PostTime,@UpdateTime
                                )", ConfigHelper.Tableprefix);

            using(var conn = new DapperHelper().OpenConnection())
            {
                conn.Execute(cmdText, post);
                return conn.Query<int>(string.Format("select  [PostId] from [{0}Posts] order by [PostId] desc limit 1", ConfigHelper.Tableprefix), null).First();
            }
        }
Exemple #7
0
        public ActionResult SavePost(PostInfo p)
        {
            int pages = PressRequest.GetFormInt("page", 1);

            p.UpdateTime = DateTime.Now;
            p.Tag = _tagService.GetTagIdList(p.Tag);
            p.UserId = CurrentUserId;
            p.PageName = TypeConverter.ObjectToString(p.PageName);
            p.Summary = TypeConverter.ObjectToString(p.Summary);
            p.Status = PressRequest.GetFormInt("chkStatus", 1);

             var action = "edit";
             if (p.PostId > 0) action += "?id=" + p.PostId;

            if (string.IsNullOrEmpty(p.Title))
            {
                ErrorNotification("标题不能为空");
                return Redirect(action);
            }
            if (string.IsNullOrEmpty(p.PostContent))
            {
                ErrorNotification("内容不能为空");
                return Redirect(action);
            }

            var isSaveMsg = PressRequest.GetFormInt("chkSaveImage",0);
            if (isSaveMsg>0)
            {
                p.PostContent = _postService.SaveRemoteImage(p.PostContent);
            }
            if (p.PostId>0)
            {
                var post = _postService.GetPost(p.PostId);
                p.ViewCount = post.ViewCount;
                p.CommentCount = post.CommentCount;
                p.PostTime = post.PostTime;

                _postService.UpdatePost(p);
                string url = "http://" + PressRequest.GetCurrentFullHost() + "/post/" + (!string.IsNullOrEmpty(p.PageName) ? p.PageName : p.PostId.ToString());
                SuccessNotification("修改成功。<a href=\"" + url + "\">查看文章</a> ");
            }
            else
            {
                p.PostTime = DateTime.Now;
                p.PostId = _postService.InsertPost(p);
                string url = "http://" + PressRequest.GetCurrentFullHost() + "/post/" + (!string.IsNullOrEmpty(p.PageName) ? p.PageName : p.PostId.ToString());
                SuccessNotification("发布成功。<a href=\"" + url + "\">查看文章</a> ");
            }
            return Redirect("edit?id="+p.PostId);
        }
        /// <summary>
        /// 添加或修改文章
        /// </summary>
        /// <param name="blogID"></param>
        /// <param name="postID"></param>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <param name="sentPost"></param>
        /// <param name="publish"></param>
        /// <param name="operate"></param>
        /// <returns></returns>
        private int NewOrUpdatePost(string blogID, string postID, string userName, string password, MWAPost sentPost, bool publish, OperateType operate)
        {
            ValidateRequest(userName, password);

            PostInfo post = new PostInfo();
            PostService _postService = new PostService();

            if (operate == OperateType.Update)
            {
                post = new PostService().GetPost(Jqpress.Framework.Utils.TypeConverter.StrToInt(postID, 0));

            }
            else
            {
                post.CommentCount = 0;
                post.ViewCount = 0;
                post.PostTime = DateTime.Now;

                UserInfo user = (new UserService()).GetUser(userName);
                if (user != null)
                {
                    post.UserId = user.UserId;
                }
            }

            post.Title = Jqpress.Framework.Web.HttpHelper.HtmlEncode(sentPost.title);
            post.PostContent = sentPost.description;
            post.Status = publish == true ? 1 : 0;
            post.PageName = Jqpress.Framework.Utils.StringHelper.FilterPageName(sentPost.pagename, "post", true);
            post.Summary = sentPost.excerpt;

            post.UrlFormat = (int)PostUrlFormat.Default;
            post.Template = string.Empty;
            post.Recommend = 0;
            post.TopStatus = 0;
            post.PostStatus = 0;
            post.UpdateTime = DateTime.Now;

            if (sentPost.commentPolicy != "")
            {
                if (sentPost.commentPolicy == "1")
                    post.CommentStatus = 1;
                else
                    post.CommentStatus = 0;
            }

            foreach (string item in sentPost.categories)
            {
                CategoryInfo cat;
                if (LookupCategoryGuidByName(item, out cat))
                {
                    post.CategoryId = cat.CategoryId;
                }
                else
                {
                    CategoryInfo newcat = new CategoryInfo();
                    newcat.PostCount = 0;
                    newcat.CreateTime = DateTime.Now;
                    newcat.Description = "由离线工具创建";
                    newcat.SortNum = 1000;
                    newcat.CateName = Jqpress.Framework.Web.HttpHelper.HtmlEncode(item);
                    newcat.PageName = Jqpress.Framework.Utils.StringHelper.FilterPageName(item, "cate", false);

                    newcat.CategoryId = new CategoryService().InsertCategory(newcat);
                    post.CategoryId = newcat.CategoryId;
                }
            }
            post.Tag = GetTagIdList(sentPost.tags);

            if (operate == OperateType.Update)
            {
                new PostService().UpdatePost(post);
            }
            else
            {
                post.PostId = new PostService().InsertPost(post);

                //    SendEmail(p);
            }

            return post.PostId;
        }
Exemple #9
0
        /// <summary>
        /// 修改文章
        /// </summary>
        /// <param name="_postinfo"></param>
        /// <returns></returns>
        public int UpdatePost(PostInfo _postinfo)
        {
            //   PostInfo oldPost = GetPost(_postinfo.PostId);   //好像有问题,不能缓存

            PostInfo oldPost = GetPost(_postinfo.PostId);

            int result = _postRepository.Update(_postinfo);

            if (oldPost != null && oldPost.CategoryId != _postinfo.CategoryId)
            {
                //分类
                new CategoryService().UpdateCategoryCount(oldPost.CategoryId, -1);
                new CategoryService().UpdateCategoryCount(_postinfo.CategoryId, 1);
            }

            //     CacheHelper.Remove(CacheKey);

            //标签
            new TagService().UpdateTagUseCount(oldPost.Tag, -1);
            new TagService().UpdateTagUseCount(_postinfo.Tag, 1);

            //   RemovePostsCache();

            return result;
        }
Exemple #10
0
        /// <summary>
        /// 发邮件
        /// </summary>
        /// <param name="post"></param>
        public void SendEmail(PostInfo post)
        {
            if (SiteConfig.GetSetting().SendMailAuthorByPost == 1)
            {
                List<UserInfo> list = new UserService().GetUserList();
                List<string> emailList = new List<string>();

                foreach (UserInfo user in list)
                {
                    if (!Jqpress.Framework.Utils.Validate.IsEmail(user.Email))
                    {
                        continue;
                    }
                    //自己不用发
                    //if (CurrentUser.Email == user.Email)
                    //{
                    //    continue;
                    //}
                    ////不重复发送
                    //if (emailList.Contains(user.Email))
                    //{
                    //    continue;
                    //}
                    //emailList.Add(user.Email);

                    //string subject = string.Empty;
                    //string body = string.Empty;

                    //subject = string.Format("[新文章通知]{0}", post.Title);
                    //body += string.Format("{0}有新文章了:<br/>", BlogConfig.GetSetting().SiteName);
                    //body += "<hr/>";
                    //body += "<br />标题: " + post.Link;
                    //body += post.Detail;
                    //body += "<hr/>";
                    //body += "<br />作者: " + CurrentUser.Link;
                    //body += "<br />时间: " + post.PostTime;
                    //body += "<br />文章连接: " + post.Link;
                    //body += "<br />注:系统自动通知邮件,不要回复。";

                    // EmailHelper.SendAsync(user.Email, subject, body);
                }
            }
        }
Exemple #11
0
        /// <summary>
        /// 添加文章
        /// </summary>
        /// <param name="post"></param>
        /// <returns></returns>
        public int InsertPost(PostInfo post)
        {
            post.PostId = _postRepository.Insert(post);

            //统计
            new StatisticsService().UpdateStatisticsPostCount(1);
            //用户
            new UserService().UpdateUserPostCount(post.UserId, 1);
            //分类
            new CategoryService().UpdateCategoryCount(post.CategoryId, 1);
            //标签
            new TagService().UpdateTagUseCount(post.Tag, 1);

            //   RemovePostsCache();
            SendEmail(post);
            return post.PostId;
        }
Exemple #12
0
        /// <summary>
        /// 获取相关文章 需要改进
        /// </summary>
        /// <param name="post"></param>
        /// <returns></returns>
        public List<PostInfo> GetRelatedPosts(PostInfo post)
        {
            List<PostInfo> list = GetPostList().FindAll(p => p.PostStatus == 0 && p.Status == 1);
            string tags = post.Tag.Replace("}", "},");
            tags = tags.TrimEnd(',');

            string[] temparray = tags.Split(',');

            int num = 0;
            var list2 = list.FindAll(p =>
            {
                if (num >= SiteConfig.GetSetting().PostRelatedCount)
                {
                    return false;
                }

                if (temparray.Any(tag => p.Tag.IndexOf(tag) != -1 && p.PostId != post.PostId))
                {
                    num++;
                    return true;
                }
                return false;

            });
            return list2;
        }