Пример #1
0
        /// <summary>
        /// ajax保存
        /// </summary>
        protected void SaveData(string act)
        {
            LinkInfo link = new LinkInfo();

            if (act == "update")
            {
                link = LinkService.GetLink(PressRequest.GetFormInt("hidLinkId", 0));
            }
            else
            {
                link.CreateTime = DateTime.Now;
                link.Type       = 0;// (int)LinkType.Custom;
            }
            link.LinkName    = HttpHelper.HtmlEncode(txtName.Text.Trim());
            link.LinkUrl     = HttpHelper.HtmlEncode(txtLinkUrl.Text.Trim());
            link.Description = HttpHelper.HtmlEncode(txtDescription.Text);
            link.SortNum     = TypeConverter.StrToInt(txtDisplayOrder.Text, 1000);
            link.Status      = chkStatus.Checked ? 1 : 0;
            link.Position    = chkPosition.Checked ? (int)LinkPosition.Navigation : (int)LinkPosition.General;
            link.Target      = chkTarget.Checked ? "_blank" : "_self";

            if (link.LinkName == "")
            {
                return;
            }

            Dictionary <string, string> jsondic = new Dictionary <string, string>();

            jsondic.Add("LinkName", link.LinkName);
            jsondic.Add("LinkUrl", link.LinkUrl);
            jsondic.Add("Description", link.Description);
            jsondic.Add("SortNum", link.SortNum.ToString());
            jsondic.Add("Position", link.Position == (int)Jqpress.Blog.Entity.Enum.LinkPosition.Navigation ? "[导航]" : "");
            jsondic.Add("Status", link.Status == 0 ? "[隐藏]" : "");


            if (act == "update")//更新操作
            {
                jsondic.Add("CreateTime", link.CreateTime.ToShortDateString());
                jsondic.Add("LinkId", link.LinkId.ToString());

                LinkService.UpdateLink(link);
                Response.Write(JsonHelper.DictionaryToJson(jsondic));
            }
            else//添加操作
            {
                int LinkId = LinkService.InsertLink(link);
                jsondic.Add("LinkId", LinkId.ToString());
                jsondic.Add("CreateTime", DateTime.Now.ToShortDateString());
                Response.Write(JsonHelper.DictionaryToJson(jsondic));
            }
            Response.End();
        }
Пример #2
0
        /// <summary>
        /// ajax保存
        /// </summary>
        protected void SaveData(string act)
        {
            TagInfo tag = new TagInfo();

            if (act == "update")
            {
                tag = TagService.GetTag(PressRequest.GetFormInt("hidTagId", 0));
            }
            else
            {
                tag.CreateTime = DateTime.Now;
                tag.PostCount  = 0;
            }

            tag.CateName    = HttpHelper.HtmlEncode(txtName.Text);
            tag.Slug        = StringHelper.FilterSlug(tag.CateName, "tag");
            tag.Description = HttpHelper.HtmlEncode(txtDescription.Text);
            tag.SortNum     = TypeConverter.StrToInt(txtDisplayOrder.Text, 1000);

            if (tag.CateName == "")
            {
                return;
            }
            Dictionary <string, string> jsondic = new Dictionary <string, string>();

            jsondic.Add("CateName", tag.CateName);
            jsondic.Add("Url", tag.Url);
            jsondic.Add("SortNum", tag.SortNum.ToString());
            jsondic.Add("Description", tag.Description);


            if (act == "update")//更新操作
            {
                jsondic.Add("Slug", tag.Slug);
                jsondic.Add("PostCount", tag.PostCount.ToString());
                jsondic.Add("CreateTime", tag.CreateTime.ToShortDateString());
                jsondic.Add("TagId", tag.TagId.ToString());

                TagService.UpdateTag(tag);
                Response.Write(JsonHelper.DictionaryToJson(jsondic));
            }
            else//添加操作
            {
                int tagid = TagService.InsertTag(tag);
                jsondic.Add("TagId", tagid.ToString());
                jsondic.Add("PostCount", "0");
                jsondic.Add("CreateTime", DateTime.Now.ToShortDateString());
                Response.Write(JsonHelper.DictionaryToJson(jsondic));
            }
            Response.End();
        }
Пример #3
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));
        }
Пример #4
0
        /// <summary>
        /// ajax保存
        /// </summary>
        protected void SaveData(string act)
        {
            Dictionary <string, string> jsondic = new Dictionary <string, string>();
            UserInfo u = new UserInfo();

            if (act == "update")
            {
                u = UserService.GetUser(PressRequest.GetFormInt("hidUserId", 0));
            }
            else
            {
                u.CommentCount = 0;
                u.CreateTime   = DateTime.Now;
                u.PostCount    = 0;
                u.UserName     = HttpHelper.HtmlEncode(txtUserName.Text.Trim());
            }

            u.Email       = HttpHelper.HtmlEncode(txtEmail.Text.Trim());
            u.SiteUrl     = string.Empty; // HttpHelper.HtmlEncode(txtSiteUrl.Text.Trim());
            u.Status      = chkStatus.Checked ? 1 : 0;
            u.Description = string.Empty; // StringHelper.TextToHtml(txtDescription.Text);
            u.UserType    = TypeConverter.StrToInt(ddlUserType.SelectedValue, 0);
            u.NickName    = HttpHelper.HtmlEncode(txtNickName.Text.Trim());
            u.AvatarUrl   = string.Empty;
            u.SortNum     = TypeConverter.StrToInt(txtSortNum.Text, 1000);

            if (!string.IsNullOrEmpty(txtPassword.Text.Trim()))
            {
                u.Password = EncryptHelper.MD5(txtPassword.Text.Trim());
            }
            if (!string.IsNullOrEmpty(txtPassword.Text.Trim()) && txtPassword.Text != txtPassword2.Text)
            {
                AjaxShowErr("两次密码输入不相同!");
            }

            jsondic.Add("UserName", u.UserName);
            jsondic.Add("UserType", GetUserType(u.UserType));
            jsondic.Add("Link", u.Link);
            jsondic.Add("SortNum", u.SortNum.ToString());
            jsondic.Add("Status", u.Status.ToString());

            if (act == "update")//更新操作
            {
                jsondic.Add("PostCount", u.PostCount.ToString());
                jsondic.Add("CommentCount", u.CommentCount.ToString());
                jsondic.Add("CreateTime", u.CreateTime.ToShortDateString());
                jsondic.Add("UserId", u.UserId.ToString());

                UserService.UpdateUser(u);

                //  如果修改自己,更新COOKIE
                if (!string.IsNullOrEmpty(txtPassword.Text.Trim()) && u.UserId == CurrentUserId)
                {
                    WriteUserCookie(u.UserId, u.UserName, u.Password, 0);
                }
                Response.Write(JsonHelper.DictionaryToJson(jsondic));
            }
            else//添加操作
            {
                #region 验证处理
                if (string.IsNullOrEmpty(u.UserName))
                {
                    AjaxShowErr("请输入登陆用户名!");
                }

                System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("[A-Za-z0-9\u4e00-\u9fa5-]");
                if (!reg.IsMatch(u.UserName))
                {
                    AjaxShowErr("用户名限字母,数字,中文,连字符!");
                }
                if (Jqpress.Framework.Utils.Validate.IsInt(u.UserName))
                {
                    AjaxShowErr("用户名不能为全数字!");
                }

                if (string.IsNullOrEmpty(u.Password))
                {
                    AjaxShowErr("请输入密码!");
                }
                if (UserService.ExistsUserName(u.UserName))
                {
                    AjaxShowErr("该登陆用户名已存在,请换之");
                }
                #endregion

                int userid = UserService.InsertUser(u);
                jsondic.Add("UserId", userid.ToString());
                jsondic.Add("PostCount", "0");
                jsondic.Add("CommentCount", "0");
                jsondic.Add("CreateTime", DateTime.Now.ToShortDateString());
                Response.Write(JsonHelper.DictionaryToJson(jsondic));
            }
            Response.End();
        }
Пример #5
0
        /// <summary>
        /// ajax保存
        /// </summary>
        protected void SaveData(string act)
        {
            CategoryInfo term = new CategoryInfo();

            if (act == "update")
            {
                term = CategoryService.GetCategory(PressRequest.GetFormInt("hidCategoryId", 0));
            }
            else
            {
                term.CreateTime = DateTime.Now;
                term.PostCount  = 0;
            }
            term.CateName = HttpHelper.HtmlEncode(txtName.Text);
            term.ParentId = Convert.ToInt32(ddlCategory.SelectedValue);
            term.Slug     = txtSlug.Text.Trim();
            if (string.IsNullOrEmpty(term.Slug))
            {
                term.Slug = term.CateName;
            }

            term.Slug = HttpHelper.HtmlEncode(StringHelper.FilterSlug(term.Slug, "cate"));

            term.Description = HttpHelper.HtmlEncode(txtDescription.Text);
            term.SortNum     = TypeConverter.StrToInt(txtDisplayOrder.Text, 1000);

            if (term.CateName == "")
            {
                return;
            }
            Dictionary <string, string> jsondic = new Dictionary <string, string>();

            jsondic.Add("CateName", term.CateName);
            jsondic.Add("Url", term.Url);
            jsondic.Add("SortNum", term.SortNum.ToString());
            jsondic.Add("Description", term.Description);


            if (act == "update")//更新操作
            {
                jsondic.Add("Slug", term.Slug);
                jsondic.Add("PostCount", term.PostCount.ToString());
                jsondic.Add("CreateTime", term.CreateTime.ToShortDateString());
                jsondic.Add("CategoryId", term.CategoryId.ToString());
                jsondic.Add("ParentId", term.ParentId.ToString());
                jsondic.Add("TreeChar", CategoryService.GetCategoryTreeList().Find(c => c.CategoryId == term.CategoryId).TreeChar);

                CategoryService.UpdateCategory(term);
                Response.Write(JsonHelper.DictionaryToJson(jsondic));
            }
            else//添加操作
            {
                int categoryid = CategoryService.InsertCategory(term);
                jsondic.Add("CategoryId", categoryid.ToString());
                jsondic.Add("PostCount", "0");
                jsondic.Add("CreateTime", DateTime.Now.ToShortDateString());
                jsondic.Add("ParentId", term.ParentId.ToString());
                jsondic.Add("TreeChar", CategoryService.GetCategoryTreeList().Find(c => c.CategoryId == categoryid).TreeChar);
                Response.Write(JsonHelper.DictionaryToJson(jsondic));
            }
            Response.End();
        }