示例#1
0
 /// <summary>
 /// Initialize controller
 /// </summary>
 /// <param name="requestContext">Request context</param>
 protected override void Initialize(System.Web.Routing.RequestContext requestContext)
 {
     base.Initialize(requestContext);
     SiteUrl = PressRequest.GetCurrentFullHost();
     string url = PressRequest.GetRawUrl();
 }
示例#2
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 rootpath = "/upfiles/titlepic";
            var file     = Request.Files["TitlePic"];
            var action   = "edit";

            if (p.PostId > 0)
            {
                action += "?id=" + p.PostId;
            }
            //todo:上传要改成自动生成文件名称,不能是中文
            if (!string.IsNullOrEmpty(file.FileName))
            {
                var orignpath = rootpath + "/" + file.FileName;
                var savepath  = Server.MapPath(orignpath);
                var ext       = FileHelper.GetFileExtName(file.FileName);
                var thumbnail = orignpath.Replace(ext, "_270X200" + ext);
                file.SaveAs(savepath);
                try
                {
                    FileHelper.MakeThumbnail(savepath, Server.MapPath(thumbnail), 270, 200, "HW", 0);
                    p.TitlePic = thumbnail;
                }
                catch (Exception e)
                {
                    ErrorNotification("标题图片格式有错误");
                    return(Redirect(action));
                }
            }


            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;
                if (string.IsNullOrEmpty(file.FileName))
                {
                    p.TitlePic = post.TitlePic;
                }

                _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));
        }