Esempio n. 1
0
        /// <summary>
        /// 分页获取 博客 内容
        /// </summary>
        /// <param name="idex">页码</param>
        /// <param name="sizePage">页容量</param>
        /// <param name="ContentLength">内容截取长度</param>
        /// <returns></returns>
        public object GetBlogContent(int index, int sizePage, int contentLength)
        {
            int total;

            BLL.BlogsBLL blog     = new BLL.BlogsBLL();
            var          bloglist = blog.GetList(index, sizePage, out total, t => t.IsShowHome == true, false, t => t.BlogCreateTime, false, tableName: t => t.BlogUsersSet)//
                                    .ToList()
                                    .Select(t => new ModelDB.Blogs()
            {
                Id             = t.Id,                                                   //博客id
                BlogTitle      = t.BlogTitle,                                            //博客标题
                BlogContent    = MyHtmlHelper.GetHtmlText(t.BlogContent, contentLength), //博客简介
                BlogCreateTime = t.BlogCreateTime,                                       //博客创建时间
                BlogUsersSet   = new ModelDB.BlogUsersSet()
                {
                    UserName     = t.BlogUsersSet.UserName,    //用户名
                    UserNickname = t.BlogUsersSet.UserNickname //昵称
                },
                BlogReadNum    = t.BlogReadNum,                //博客阅读量
                BlogCommentNum = t.BlogCommentNum              //博客评论量
            }).ToList();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("BlogBrief", bloglist); //博客简介
            dic.Add("Total", total);        //总页数
            //dic.Add("users", CacheData.GetAllUserInfo().Where(t => t.IsLock == false).Select(t => new
            //    {
            //        UserName = t.UserName,
            //        UserImage = t.UserImage,
            //        UserNickname = t.UserNickname
            //    }
            //    ).ToList());
            return(dic);
        }
Esempio n. 2
0
        /// <summary>
        /// (弃用)
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="sizePage">页容量</param>
        /// <param name="ContentLength">内容截取长度</param>
        /// <returns></returns>
        public object Get(int idex, int sizePage, int ContentLength)
        {
            int total;

            BLL.BlogsBLL blog     = new BLL.BlogsBLL();
            var          bloglist = blog.GetList(idex, sizePage, out total, t => t.IsShowHome == true, false, t => t.BlogCreateTime, false, tableName: t => t.BlogUsersSet)//
                                    .ToList()
                                    .Select(t => new ModelDB.Blogs()
            {
                Id             = t.Id,
                BlogTitle      = t.BlogTitle,
                BlogContent    = MyHtmlHelper.GetHtmlText(t.BlogContent, ContentLength),
                BlogCreateTime = t.BlogCreateTime,
                BlogUsersSet   = new ModelDB.BlogUsersSet()
                {
                    UserName     = t.BlogUsersSet.UserName,
                    UserNickname = t.BlogUsersSet.UserNickname
                },
                BlogReadNum    = t.BlogReadNum,
                BlogCommentNum = t.BlogCommentNum
            }).ToList();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("blog", bloglist);
            dic.Add("total", total);
            //dic.Add("users", CacheData.GetAllUserInfo().Where(t => t.IsLock == false).ToList());
            //dic.Add("SessionUser", BLL.Common.BLLSession.UserInfoSessioin);
            return(dic);
        }
Esempio n. 3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        List <IndexCard>[] ls = ArticleHelper.IndexCards("");
        //绑定学院新闻
        rptCollege.DataSource = ls[0];
        rptCollege.DataBind();
        //绑定学生新闻
        rptStudent.DataSource = ls[1];
        rptStudent.DataBind();
        //绑定通知公告
        rptNotice1.DataSource = ArticleHelper.getList(0, ls[2]);
        rptNotice1.DataBind();
        rptNotice2.DataSource = ArticleHelper.getList(1, ls[2]);
        rptNotice2.DataBind();
        //绑定招聘资讯
        rptJob1.DataSource = ArticleHelper.getList(0, ls[3]);
        rptJob1.DataBind();
        rptJob2.DataSource = ArticleHelper.getList(1, ls[3]);
        rptJob2.DataBind();
        //绑定学术报告部分
        //string content = ArticleHelper.getReporter().Content;
        int id = ArticleHelper.getReporterID();

        if (id == 0)
        {
            pnAcademic.Visible = false;
        }
        else
        {
            Article  ar  = ArticleHelper.GetArticleByID(id);
            string[] all = ar.Content.Split(new char[] { '!', '#' });
            ltTitle.Text = ar.Title;
            string lt = MyHtmlHelper.RemoveTags(ar.Content.Substring(ar.Content.IndexOf('#')));
            ltContent.Text = lt.Length > 40 ? lt.Substring(1, 39) : lt.Substring(1, lt.Length - 1);
            if (ar.Link == null)
            {
                lbtReporter.PostBackUrl = "Content.aspx?id=" + ar.ArticleID;
            }
            else
            {
                lbtReporter.PostBackUrl = ar.Link;
            }
            //时间---
            string month = all[0].Substring(5, 2);
            if (month[0] == '0')
            {
                month = month.Substring(1, 1);
            }
            string day = all[0].Substring(8, 2);
            if (day[0] == '0')
            {
                day = day.Substring(1, 1);
            }
            ltTime.Text  = month + "." + day + " " + all[1];
            ltPlace.Text = all[2];
        }
    }
 protected void rptActivitySummary_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         //绑定序号
         Literal literal = (Literal)e.Item.FindControl("ltNumber");
         literal.Text = (e.Item.ItemIndex + 1).ToString();
         //绑定内容
         literal = (Literal)e.Item.FindControl("ltContent");
         string content = MyHtmlHelper.RemoveTags(Server.HtmlDecode(literal.Text));
         literal.Text = content.Length > 40 ? content.Substring(0, 40) + "..." : content;
     }
 }
Esempio n. 5
0
        public ActionResult Index(int?id)
        {
            //
            int total;

            Response.Cache.SetOmitVaryStar(true);
            id = id ?? 1;
            int idex = int.Parse(id.ToString());

            BLL.BlogsBLL blog     = new BLL.BlogsBLL();
            var          bloglist = blog.GetList <DateTime?>(idex, sizePage, out total, t => t.IsShowHome == true, false, t => t.BlogCreateTime, false)
                                    .Select(t => new
            {
                Id             = t.Id,
                BlogTitle      = t.BlogTitle,
                BlogContent    = t.BlogContent,
                UserName       = t.BlogUsersSet.UserName,
                UserNickname   = t.BlogUsersSet.UserNickname,
                BlogCreateTime = t.BlogCreateTime,
                BlogReadNum    = t.BlogReadNum,
                BlogCommentNum = t.BlogCommentNum
            })
                                    .ToList()
                                    .Select(t => new ModelDB.Blogs()
            {
                Id             = t.Id,
                BlogTitle      = t.BlogTitle,
                BlogContent    = MyHtmlHelper.GetHtmlText(t.BlogContent),
                BlogCreateTime = t.BlogCreateTime,
                BlogUsersSet   = new ModelDB.BlogUsersSet()
                {
                    UserName     = t.UserName,
                    UserNickname = t.UserNickname
                },
                BlogReadNum    = t.BlogReadNum,
                BlogCommentNum = t.BlogCommentNum
            }).ToList();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("blog", bloglist);
            dic.Add("users", CacheData.GetAllUserInfo().Where(t => t.IsLock == false).ToList());
            dic.Add("SessionUser", BLL.Common.BLLSession.UserInfoSessioin);
            dic.Add("total", total);
            return(View(dic));
        }
Esempio n. 6
0
        public ActionResult GetTagBlogs(int id, string name, int?typeId)
        {
            Response.Cache.SetOmitVaryStar(true);
            BLL.BaseBLL <BlogTag> tagbll = new BLL.BaseBLL <BlogTag>();
            var tag = tagbll.GetList(t => t.Id == typeId && t.BlogUser.UserName == name).FirstOrDefault();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            if (tag != null)
            {
                //这里因为 是直接 分页查询        所以一定要记住 过滤 isdel
                var listblog = tag.BlogInfos.Where(t => t.IsDelte == false).OrderByDescending(t => t.BlogCreateTime).Skip((id - 1) * sizePage).Take(sizePage)
                               .Select(t => new
                {
                    BlogContent    = t.Content,
                    BlogCreateTime = t.BlogCreateTime,
                    BlogTitle      = t.Title,
                    Id             = t.Id,
                    BlogReadNum    = t.ReadNum,
                    BlogCommentNum = t.CommentNum
                })
                               .ToList()
                               .Select(t => new BlogInfo()
                {
                    Id             = t.Id,
                    Title          = t.BlogTitle,
                    BlogCreateTime = t.BlogCreateTime,
                    Content        = MyHtmlHelper.GetHtmlText(t.BlogContent),
                    ReadNum        = t.BlogReadNum,
                    CommentNum     = t.BlogCommentNum
                })
                               .ToList();
                dic.Add("blog", listblog);
                dic.Add("tag", tag.TagName);

                int mcount = tag.BlogInfos.Count();
                int total  = (mcount / sizePage) + (mcount % sizePage > 0 ? 1 : 0);
                dic.Add("total", total);

                SetDic(dic, name);
                return(View(dic));
            }
            return(View());
        }
        public ActionResult GetTypeBlogs(int id, string name, int?typeId)
        {
            Response.Cache.SetOmitVaryStar(true);
            BLL.BlogTypesBLL typebll = new BLL.BlogTypesBLL();
            var type = typebll.GetList(t => t.Id == typeId && t.BlogUsersSet.UserName == name).FirstOrDefault();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            if (type != null)
            {
                var listblog = type.Blogs.Where(t => t.IsDel == false).OrderByDescending(t => t.BlogCreateTime).Skip((id - 1) * sizePage).Take(sizePage)
                               .Select(t => new
                {
                    BlogCreateTime = t.BlogCreateTime,
                    BlogContent    = t.BlogContent,
                    BlogTitle      = t.BlogTitle,
                    Id             = t.Id,
                    BlogReadNum    = t.BlogReadNum,
                    BlogCommentNum = t.BlogCommentNum
                })
                               .ToList()
                               .Select(t => new ModelDB.Blogs()
                {
                    Id             = t.Id,
                    BlogTitle      = t.BlogTitle,
                    BlogCreateTime = t.BlogCreateTime,
                    BlogContent    = MyHtmlHelper.GetHtmlText(t.BlogContent),
                    BlogReadNum    = t.BlogReadNum,
                    BlogCommentNum = t.BlogCommentNum
                })
                               .ToList();
                dic.Add("blog", listblog);
                dic.Add("type", type.TypeName);

                int mcount = type.Blogs.Count();
                int total  = (mcount / sizePage) + (mcount % sizePage > 0 ? 1 : 0);
                dic.Add("total", total);

                SetDic(dic, name);
                return(View(dic));
            }
            return(View());
        }
Esempio n. 8
0
        public ActionResult UserBlogList(string name, int?id)
        {
            //加不加 Response.Cache.SetOmitVaryStar(true),服务端的缓存情况都是一样的。
            //只是不加 SetOmitVaryStar(true) 时,对于同一个客户端浏览器,每隔一次请求,服务器端就不管客户端浏览器的缓存,
            //重新发送页面内容,但是只要在缓存有效期内,内容还是从服务器端缓存中读取。
            //http://www.cnblogs.com/dudu/archive/2012/08/27/asp_net_mvc_outputcache.html
            Response.Cache.SetOmitVaryStar(true);
            int myid = id ?? 1;

            BLL.BaseBLL <BlogInfo> blog = new BLL.BaseBLL <BlogInfo>();
            var bloglist = blog.GetList <DateTime?>(myid, sizePage, out total, t => t.User.UserName == name && t.IsShowMyHome == true, false, t => t.BlogCreateTime, false)
                           .Select(t => new
            {
                Id             = t.Id,
                BlogTitle      = t.Title,
                BlogContent    = t.Content,
                BlogCreateTime = t.BlogCreateTime,
                BlogReadNum    = t.ReadNum,
                BlogCommentNum = t.CommentNum
            })
                           .ToList()
                           .Select(t => new BlogInfo()
            {
                Id             = t.Id,
                Title          = t.BlogTitle,
                Content        = MyHtmlHelper.GetHtmlText(t.BlogContent),
                BlogCreateTime = t.BlogCreateTime,
                ReadNum        = t.BlogReadNum,
                CommentNum     = t.BlogCommentNum
            }).ToList();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("blogList", bloglist);
            //dic.Add("blogUserName", name);
            dic.Add("total", total);
            SetDic(dic, name);
            return(View(dic));
        }
Esempio n. 9
0
 protected void rptService_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         //绑定序号
         Literal literal = (Literal)e.Item.FindControl("ltNumber");
         literal.Text = (e.Item.ItemIndex + 1).ToString();
         //绑定分类
         try
         {
             literal      = (Literal)e.Item.FindControl("ltCategory");
             literal.Text = DevelopHelper.getCategoryName(Convert.ToInt32(literal.Text));
         }
         catch
         {
             literal.Text = "";
         }
         //绑定内容
         literal = (Literal)e.Item.FindControl("ltContent");
         string content = MyHtmlHelper.RemoveTags(Server.HtmlDecode(literal.Text));
         literal.Text = content.Length > 40 ? content.Substring(0, 40) + "..." : content;
     }
 }
        [CacheOutput(ClientTimeSpan = 120, ServerTimeSpan = 120)]//120 两分钟
        public object GetBlogContent(int index, int sizePage, int contentLength, int userId = -1)
        {
            int total;

            BLL.BaseBLL <BlogInfo> blog         = new BLL.BaseBLL <BlogInfo>();
            IQueryable <BlogInfo>  bloglistTemp = null;

            if (userId > 0)//个人用户首页
            {
                bloglistTemp = blog.GetList(index, sizePage, out total, t => t.IsShowMyHome == true && t.User.Id == userId, false, t => t.BlogCreateTime, false, tableName: t => t.User);
            }
            else//首页
            {
                bloglistTemp = blog.GetList(index, sizePage, out total, t => t.IsShowHome == true, false, t => t.BlogCreateTime, false, tableName: t => t.User);//
            }
            var bloglist = bloglistTemp.ToList()
                           .Select(t => new BlogInfo()
            {
                Id             = t.Id,                                               //博客id
                Title          = t.Title,                                            //博客标题
                Content        = MyHtmlHelper.GetHtmlText(t.Content, contentLength), //博客简介
                BlogCreateTime = t.BlogCreateTime,                                   //博客创建时间
                User           = new BlogUser()
                {
                    UserName     = t.User.UserName,    //用户名
                    UserNickname = t.User.UserNickname //昵称
                },
                ReadNum    = t.ReadNum,                //博客阅读量
                CommentNum = t.CommentNum              //博客评论量
            }).ToList();

            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("BlogBrief", bloglist); //博客简介
            dic.Add("Total", total);        //总页数
            return(dic);
        }
Esempio n. 11
0
        public string Release()
        {
            JSData jsdata = new JSData();

            var content    = Request.Form["content"];    //正文内容
            var title      = Request.Form["title"];      //标题
            var oldtag     = Request.Form["oldtag"];     //旧的标签(从checkbox中选取的)
            var newtag     = Request.Form["newtag"];     //新的标签(在tag_text中输入的)
            var type       = Request.Form["chk_type"];   //文章类型
            var isshowhome = Request.Form["isshowhome"]; //是否显示在主页
            var blogid     = Request.Form["blogid"];     //

            int numblogid = -1;

            int.TryParse(blogid, out numblogid);

            #region 数据验证
            if (null == BLL.Common.BLLSession.UserInfoSessioin)
            {
                jsdata.Message = "您还未登录~";
            }

            /*else if (BLL.Common.BLLSession.UserInfoSessioin.IsLock)
             *  jsdata.Message = "您的账户未激活,暂只能评论。~";*/
            else if (string.IsNullOrEmpty(content))
            {
                jsdata.Message = "内容不能为空~";
            }
            else if (content.Length >= 300000)
            {
                jsdata.Message = "发布内容过多~";
            }
            else if (string.IsNullOrEmpty(title))
            {
                jsdata.Message = "标题不能为空~";
            }
            else if (title.Length >= 100)
            {
                jsdata.Message = "标题过长~";
            }

            if (!string.IsNullOrEmpty(jsdata.Message))
            {
                jsdata.State = EnumState.失败;
                return(jsdata.ToJson());
            }
            #endregion

            BLL.BlogsBLL blogbll       = new BLL.BlogsBLL();
            var          blogtemp      = blogbll.GetList(t => t.BlogId == numblogid, isAsNoTracking: false).FirstOrDefault();
            var          userid        = numblogid > 0 ? blogtemp.UserId : BLLSession.UserInfoSessioin.UserId;//如果numblogid大于〇证明 是编辑修改
            var          sessionuserid = BLLSession.UserInfoSessioin.UserId;

            //获取得 文章 类型
            BlogTypes myBlogType;
            if (type == null)
            {
                myBlogType = new BlogTypesBLL().GetList(t => (t.TypeName == "未分类" && t.UserId == BLLSession.UserInfoSessioin.UserId), isAsNoTracking: false).FirstOrDefault();
            }
            else
            {
                var blogtype = int.Parse(type);
                myBlogType = new BLL.BlogTypesBLL().GetList(t => t.BlogTypeId == blogtype, isAsNoTracking: false).ToList().FirstOrDefault();
            }
            //获取得 文章 tag标签集合 对象
            //old
            var oldtaglist = oldtag.Split(',').ToList();
            var myOldTag   = new BLL.BlogTagsBLL().GetList(t => t.UserId == userid && oldtaglist.Contains(t.BlogTagName), isAsNoTracking: false).ToList();
            //new
            var newtaglistname = newtag.Split(',').ToList();

            //保存newtags到数据库
            BlogTagsBLL   tagBLL       = new BlogTagsBLL();
            List <string> distinctTemp = new List <string>();
            foreach (string tagName in newtaglistname)
            {
                if (String.IsNullOrEmpty(tagName.Trim()))
                {
                    continue;
                }
                if (distinctTemp.Contains(tagName.Trim()))
                {
                    continue;
                }
                tagBLL.Add(new BlogTags
                {
                    BlogTagName = tagName.Trim(),
                    UserId      = userid
                });
                try { tagBLL.save(); }
                catch (Exception ex)
                {
                    jsdata.Message = ex.ToString();
                    jsdata.State   = EnumState.失败;
                    return(jsdata.ToJson());
                }
                distinctTemp.Add(tagName.Trim());
                BLL.DataCache.GetAllTag(true);
            }
            //////////////////////

            var myTags = new BLL.BlogTagsBLL().GetList(t => t.UserId == userid && newtaglistname.Contains(t.BlogTagName), isAsNoTracking: false).ToList();
            myOldTag.ForEach(t => myTags.Add(t));



            //ModelDB.Blogs blogtemp = new ModelDB.Blogs();
            if (numblogid > 0)  //如果有 blogid 则修改
            {
                //blog = blogbll.GetList(t => t.Id == numblogid, isAsNoTracking: false).FirstOrDefault();
                if (sessionuserid == blogtemp.UserId || BLLSession.UserInfoSessioin.UserName == admin) //一定要验证更新的博客是否是登陆的用户
                {
                    blogtemp.Content     = content;
                    blogtemp.BlogRemarks = MyHtmlHelper.GetHtmlText(content);
                    blogtemp.Title       = title;
                    blogtemp.IsShowHome  = isshowhome == "true";
                    blogtemp.BlogTypes   = myBlogType;
                    blogtemp.BlogTags.Clear();//更新之前要清空      否则会存在主外键约束异常
                    blogtemp.BlogTags     = myTags;
                    blogtemp.IsDel        = false;
                    blogtemp.IsForwarding = false;
                    jsdata.Message        = "修改成功~";
                }
                else
                {
                    jsdata.Message = "您没有编辑此博文的权限~";
                    jsdata.JSurl   = "/";
                    jsdata.State   = EnumState.失败;
                    return(jsdata.ToJson());
                }
            }
            else  //否则是新发布
            {
                var blogfirst = blogbll.GetList(t => t.UserId == sessionuserid).OrderByDescending(t => t.BlogId).FirstOrDefault();
                //var blogtitle = blogtemp.BlogTitle;
                //if (blogfirst != null)
                //    blogtitle = blogtemp.BlogTitle;
                if (null != blogfirst && blogfirst.Title == title)
                {
                    jsdata.Message = "不能同时发表两篇一样标题的文章~";
                }
                else
                {
                    blogtemp = new Blogs()
                    {
                        UserId       = sessionuserid,
                        Content      = content,
                        BlogRemarks  = MyHtmlHelper.GetHtmlText(content),
                        Title        = title,
                        IsShowHome   = isshowhome == "true",
                        BlogTypes    = myBlogType,
                        BlogTags     = myTags,
                        IsDel        = false,
                        IsForwarding = false
                    };
                    blogbll.Add(blogtemp);
                    jsdata.Message = "发布成功~";
                }
            }

            //
            try
            {
                if (blogbll.save(false) > 0)
                {
                    blogtemp.BlogUrl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.BlogId + ".html";
                    blogbll.save();
                    BLL.DataCache.GetAllType(true);
                    #region 添加 或 修改搜索索引

                    var newtagList = string.Empty;
                    blogtemp.BlogTags.Where(t => true).ToList().ForEach(t => newtagList += t.BlogTagName + " ");
                    var newblogurl = "/" + BLLSession.UserInfoSessioin.UserName + "/" + blogtemp.BlogId + ".html";
                    //    SearchResult search = new SearchResult()
                    //    {
                    //        flag = blogtemp.UsersId,
                    //        id = blogtemp.Id,
                    //        title = blogtemp.BlogTitle,
                    //        clickQuantity = 0,
                    //        blogTag = newtagList,
                    //        content = Blogs.Common.Helper.MyHtmlHelper.GetHtmlText(blogtemp.BlogContent),
                    //        url = newblogurl
                    //    };
                    //    SafetyWriteHelper<SearchResult>.logWrite(search, PanGuLuceneHelper.instance.CreateIndex);
                    //

                    #endregion
                    jsdata.State = EnumState.成功;
                    jsdata.JSurl = "/" + DataCache.GetUsersInfo().Where(t => t.UserId == blogtemp.UserId).First().UserName + "/" + blogtemp.BlogId + ".html";
                    return(jsdata.ToJson());
                }
            }
            catch (Exception ex)
            {
                jsdata.State   = EnumState.失败;
                jsdata.Message = ex.ToString();
                return(jsdata.ToJson());
            }

            jsdata.State = EnumState.失败;
            return(jsdata.ToJson());
        }
Esempio n. 12
0
        public async Task <IActionResult> UpdateNoteTitleAndContent(string token, string noteId, string noteTitle, string content, string dataSignJson, string digitalEnvelopeJson)
        {
            var user = tokenSerivce.GetUserByToken(token);
            var re   = new ApiRe();

            if (user == null)
            {
                return(LeanoteJson(re));
            }
            DigitalEnvelope digitalEnvelope = null;
            var             verify          = false;

            if (this.config.SecurityConfig.ForceDigitalEnvelope)
            {
                //数字信封
                if (this.config.SecurityConfig.ForceDigitalEnvelope)
                {
                    digitalEnvelope = DigitalEnvelope.FromJSON(digitalEnvelopeJson);
                    var data = digitalEnvelope.GetPayLoadValue(this.gMService, this.config.SecurityConfig.PrivateKey);
                    if (data == null)
                    {
                        throw new Exception("数字信封解密失败");
                    }
                    //赋予解密的数字信封
                    content = data;
                }
            }

            if (this.config.SecurityConfig.ForceDigitalSignature)
            {
                //验证签名
                var dataSign = DataSignDTO.FromJSON(dataSignJson);
                verify = await this.ePassService.VerifyDataSign(dataSign);

                if (!verify)
                {
                    return(LeanoteJson(re));
                }
                verify = dataSign.SignData.Operate.Equals("/api/Note/UpdateNoteTitleAndContent");
                if (!verify)
                {
                    re.Msg = "Operate is not Equals ";
                    return(LeanoteJson(re));
                }
                //签字签名和数字信封数据
                if (dataSign != null)
                {
                    var dataSM3 = gMService.SM3(noteId + noteTitle + content);
                    var signSM3 = dataSign.SignData.Hash;
                    if (!dataSM3.ToUpper().Equals(signSM3.ToUpper()))
                    {
                        re.Msg = "SM3 is error";
                        re.Ok  = false;
                        return(LeanoteJson(re));
                    }
                }

                //签名存证
                this.dataSignService.AddDataSign(dataSign, "UpdateNoteTitleAndContent");
            }

            //-------------校验参数合法性
            if (user == null)
            {
                re.Msg = "NOlogin";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }

            // 先判断USN的问题, 因为很可能添加完附件后, 会有USN冲突, 这时附件就添错了
            var note = noteService.GetNote(noteId.ToLongByHex(), user.UserId);

            verify = noteRepositoryService.Verify(note.NotesRepositoryId, user.UserId, RepositoryAuthorityEnum.Write);
            if (!verify)
            {
                return(LeanoteJson(re));
            }

            if (note == null || note.NoteId == 0)
            {
                re.Msg = "notExists";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            var des = MyHtmlHelper.SubHTMLToRaw(content, 200);

            var noteContentId = idGenerator.NextId();

            NoteContent noteContent = new NoteContent()
            {
                NoteContentId = noteContentId,
                Abstract      = content,
                Content       = content,

                UserId        = user.UserId,
                NoteId        = note.NoteId,
                CreatedTime   = DateTime.Now,
                UpdatedTime   = DateTime.Now,
                UpdatedUserId = user.UserId
            };

            if (this.config.SecurityConfig.DataBaseEncryption)
            {
                noteContent.Abstract = "DataBaseEncryption";
            }

            noteContentService.UpdateNoteContent(note.NoteId, noteContent);

            noteService.UpdateNoteTitle(note.NoteId, noteTitle);

            var usn = noteRepositoryService.IncrUsn(note.NotesRepositoryId);

            noteService.UpdateUsn(note.NoteId, usn);
            re.Ok   = true;
            re.Data = note;
            if (this.config.SecurityConfig.ForceDigitalEnvelope)
            {
                var key  = digitalEnvelope.getSM4Key(this.gMService, this.config.SecurityConfig.PrivateKey);
                var json = note.ToJson();

                var payLoad = new PayLoadDTO();
                payLoad.SetData(json);

                var payLoadJson = payLoad.ToJson();

                var jsonHex = Common.Utils.HexUtil.ByteArrayToString(Encoding.UTF8.GetBytes(payLoadJson));

                var enc = gMService.SM4_Encrypt_CBC(jsonHex, key, digitalEnvelope.IV, true);
                re.Data       = enc;
                re.Encryption = true;
            }

            return(LeanoteJson(re));
        }
Esempio n. 13
0
        public JsonResult UpdateNote(ApiNote noteOrContent, string token)
        {
            Note noteUpdate     = new Note();
            var  needUpdateNote = false;
            var  re             = new ReUpdate();
            long?tokenUserId    = GetUserIdByToken(token);
            var  noteId         = noteOrContent.NoteId.ToLongByHex();

            //-------------校验参数合法性
            if (tokenUserId == 0)
            {
                re.Msg = "NOlogin";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }

            if (string.IsNullOrEmpty(noteOrContent.NoteId))
            {
                re.Msg = "noteIdNotExists";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }

            if (noteOrContent.Usn < 1)
            {
                re.Msg = "usnNotExists";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            // 先判断USN的问题, 因为很可能添加完附件后, 会有USN冲突, 这时附件就添错了
            var note        = noteService.GetNote(noteId, tokenUserId);
            var noteContent = noteContentService.GetNoteContent(note.NoteId, tokenUserId, false);

            if (note == null || note.NoteId == 0)
            {
                re.Msg = "notExists";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            //判断服务器版本与客户端版本是否一致
            if (note.Usn != noteOrContent.Usn)
            {
                re.Msg = "conflict";
                re.Ok  = false;
                return(Json(re, MyJsonConvert.GetSimpleOptions()));
            }
            //-------------更新文件和附件内容
            if (noteOrContent.Files != null && noteOrContent.Files.Length > 0)
            {
                for (int i = 0; i < noteOrContent.Files.Length; i++)
                {
                    var file = noteOrContent.Files[i];
                    if (file.HasBody)
                    {
                        if (!string.IsNullOrEmpty(file.LocalFileId))
                        {
                            var result = UploadImages("FileDatas[" + file.LocalFileId + "]", tokenUserId, noteId, file.IsAttach, out long?serverFileId, out string msg);
                            if (!result)
                            {
                                if (string.IsNullOrEmpty(msg))
                                {
                                    re.Msg = "fileUploadError";
                                }
                                if (!string.Equals(msg, "notImage", System.StringComparison.OrdinalIgnoreCase))
                                {
                                    return(Json(re, MyJsonConvert.GetLeanoteOptions()));
                                }
                            }
                            else
                            {
                                // 建立映射
                                file.FileId            = serverFileId.ToHex24();
                                noteOrContent.Files[i] = file;
                            }
                        }
                        else
                        {
                            return(Json(new ReUpdate()
                            {
                                Ok = false,
                                Msg = "LocalFileId_Is_NullOrEmpty",
                                Usn = 0
                            }, MyJsonConvert.GetSimpleOptions()));
                        }
                    }
                }
            }
            //更新用户元数据
            //int usn = UserService.IncrUsn(tokenUserId);

            // 移到外面来, 删除最后一个file时也要处理, 不然总删不掉
            // 附件问题, 根据Files, 有些要删除的, 只留下这些
            if (noteOrContent.Files != null)
            {
                attachService.UpdateOrDeleteAttachApiAsync(noteId, tokenUserId, noteOrContent.Files);
            }
            //-------------更新笔记内容
            var  afterContentUsn = 0;
            var  contentOk       = false;
            var  contentMsg      = "";
            long?contentId       = 0;

            if (noteOrContent.Content != null)
            {
                // 把fileId替换下
                FixPostNotecontent(ref noteOrContent);
                // 如果传了Abstract就用之
                if (noteOrContent.Abstract != null)
                {
                    noteOrContent.Abstract = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Abstract, 200);
                }
                else
                {
                    noteOrContent.Abstract = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Content, 200);
                }
            }
            else
            {
                noteOrContent.Abstract = MyHtmlHelper.SubHTMLToRaw(noteContent.Content, 200);
            }
            //上传noteContent的变更
            contentOk = noteContentService.UpdateNoteContent(
                noteOrContent,
                out contentMsg,
                out contentId
                );
            //返回处理结果
            if (!contentOk)
            {
                re.Ok  = false;
                re.Msg = contentMsg;
                re.Usn = afterContentUsn;
                return(Json(re, MyJsonConvert.GetLeanoteOptions()));
            }

            //-------------更新笔记元数据
            int afterNoteUsn = 0;
            var noteOk       = false;
            var noteMsg      = "";

            noteOk = noteService.UpdateNote(
                ref noteOrContent,
                tokenUserId,
                contentId,
                true,
                true,
                out noteMsg,
                out afterNoteUsn
                );
            if (!noteOk)
            {
                re.Ok  = false;
                re.Msg = noteMsg;
                return(Json(re, MyJsonConvert.GetLeanoteOptions()));
            }
            //处理结果
            //-------------API返回客户端信息
            note = noteService.GetNote(noteId, tokenUserId);
            // noteOrContent.NoteId = noteId.ToHex24();
            // noteOrContent.UserId = tokenUserId.ToHex24();
            //  noteOrContent.Title = note.Title;
            // noteOrContent.Tags = note.Tags;
            // noteOrContent.IsMarkdown = note.IsMarkdown;
            // noteOrContent.IsBlog = note.IsBlog;
            //noteOrContent.IsTrash = note.IsTrash;
            //noteOrContent.IsDeleted = note.IsDeleted;
            //noteOrContent.IsTrash = note.IsTrash;

            //noteOrContent.Usn = note.Usn;
            //noteOrContent.CreatedTime = note.CreatedTime;
            //noteOrContent.UpdatedTime = note.UpdatedTime;
            //noteOrContent.PublicTime = note.PublicTime;

            noteOrContent.Content     = "";
            noteOrContent.Usn         = afterNoteUsn;
            noteOrContent.UpdatedTime = DateTime.Now;
            noteOrContent.IsDeleted   = false;
            noteOrContent.UserId      = tokenUserId.ToHex24();
            return(Json(noteOrContent, MyJsonConvert.GetLeanoteOptions()));
        }
Esempio n. 14
0
        public async Task <IActionResult> AddNote(ApiNote noteOrContent, string token)
        {
            var re = new ApiRe();

            var user = tokenSerivce.GetUserByToken(token);

            if (user == null)
            {
                return(LeanoteJson(re));
            }

            //json 返回状态乱

            long?tokenUserId = GetUserIdByToken(token);;
            long?myUserId    = tokenUserId;

            if (noteOrContent == null || string.IsNullOrEmpty(noteOrContent.NotebookId))
            {
                return(Json(new ApiRe()
                {
                    Ok = false, Msg = "notebookIdNotExists"
                }, MyJsonConvert.GetSimpleOptions()));
            }
            long?noteId = idGenerator.NextId();

            if (noteOrContent.Title == null)
            {
                noteOrContent.Title = "无标题";
            }

            // TODO 先上传图片/附件, 如果不成功, 则返回false
            //-------------新增文件和附件内容
            int attachNum = 0;

            if (noteOrContent.Files != null && noteOrContent.Files.Length > 0)
            {
                for (int i = 0; i < noteOrContent.Files.Length; i++)
                {
                    var file = noteOrContent.Files[i];
                    if (file.HasBody)
                    {
                        if (!string.IsNullOrEmpty(file.LocalFileId))
                        {
                            var result = UploadImages("FileDatas[" + file.LocalFileId + "]", tokenUserId, noteId, file.IsAttach, out long?serverFileId, out string msg);
                            if (!result)
                            {
                                if (string.IsNullOrEmpty(msg))
                                {
                                    re.Msg = "fileUploadError";
                                }
                                else
                                {
                                    re.Msg = msg;
                                    return(Json(re, MyJsonConvert.GetLeanoteOptions()));
                                }
                            }
                            else
                            {
                                // 建立映射
                                file.FileId            = serverFileId.ToHex24();
                                noteOrContent.Files[i] = file;
                                if (file.IsAttach)
                                {
                                    attachNum++;
                                }
                            }
                        }
                        else
                        {   //存在疑问
                            return(Json(new ReUpdate()
                            {
                                Ok = false,
                                Msg = "LocalFileId_Is_NullOrEmpty",
                                Usn = 0
                            }, MyJsonConvert.GetSimpleOptions()));
                        }
                    }
                }
            }
            else
            {
            }
            //-------------替换笔记内容中的文件ID
            FixPostNotecontent(ref noteOrContent);
            if (noteOrContent.Tags != null)
            {
                if (noteOrContent.Tags.Length > 0 && noteOrContent.Tags[0] == null)
                {
                    noteOrContent.Tags = Array.Empty <string>();
                    //noteOrContent.Tags= new string[] { ""};
                }
            }
            //-------------新增笔记对象
            Note note = new Note()
            {
                UserId        = tokenUserId,
                NoteId        = noteId,
                CreatedUserId = tokenUserId,
                UpdatedUserId = noteId,
                NotebookId    = noteOrContent.NotebookId.ToLongByHex(),
                Title         = noteOrContent.Title,
                Tags          = noteOrContent.Tags,
                Desc          = noteOrContent.Desc,
                IsBlog        = noteOrContent.IsBlog.GetValueOrDefault(),
                IsMarkdown    = noteOrContent.IsMarkdown.GetValueOrDefault(),
                AttachNum     = attachNum,
                CreatedTime   = noteOrContent.CreatedTime,
                UpdatedTime   = noteOrContent.UpdatedTime,
                ContentId     = idGenerator.NextId()
            };

            //-------------新增笔记内容对象
            NoteContent noteContent = new NoteContent()
            {
                NoteContentId = note.ContentId,
                NoteId        = noteId,
                UserId        = tokenUserId,
                IsBlog        = note.IsBlog,
                Content       = noteOrContent.Content,
                Abstract      = noteOrContent.Abstract,
                CreatedTime   = noteOrContent.CreatedTime,
                UpdatedTime   = noteOrContent.UpdatedTime,
                IsHistory     = false
            };

            //-------------得到Desc, abstract
            if (string.IsNullOrEmpty(noteOrContent.Abstract))
            {
                if (noteOrContent.IsMarkdown.GetValueOrDefault())
                {
                    // note.Desc = MyHtmlHelper.SubMarkDownToRaw(noteOrContent.Content, 200);
                    noteContent.Abstract = MyHtmlHelper.SubMarkDownToRaw(noteOrContent.Content, 200);
                }
                else
                {
                    //note.Desc = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Content, 200);
                    noteContent.Abstract = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Content, 200);
                }
            }
            else
            {
                note.Desc = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Abstract, 200);
            }
            if (noteOrContent.Desc == null)
            {
                if (noteOrContent.IsMarkdown.GetValueOrDefault())
                {
                    note.Desc = MyHtmlHelper.SubMarkDownToRaw(noteOrContent.Content, 200);
                }
                else
                {
                    note.Desc = MyHtmlHelper.SubHTMLToRaw(noteOrContent.Content, 200);
                }
            }
            else
            {
                note.Desc = noteOrContent.Desc;
            }

            note = noteService.AddNoteAndContent(note, noteContent, myUserId);
            //-------------将笔记与笔记内容保存到数据库
            if (note == null || note.NoteId == 0)
            {
                return(Json(new ApiRe()
                {
                    Ok = false,
                    Msg = "AddNoteAndContent_is_error"
                }));
            }
            //-------------API返回客户端信息
            noteOrContent.NoteId      = noteId.ToHex24();
            noteOrContent.UserId      = tokenUserId.ToHex24();
            noteOrContent.Title       = note.Title;
            noteOrContent.Tags        = note.Tags;
            noteOrContent.IsMarkdown  = note.IsMarkdown;
            noteOrContent.IsBlog      = note.IsBlog;
            noteOrContent.IsTrash     = note.IsTrash;
            noteOrContent.IsDeleted   = note.IsDeleted;
            noteOrContent.IsTrash     = note.IsTrash;
            noteOrContent.IsTrash     = note.IsTrash;
            noteOrContent.Usn         = note.Usn;
            noteOrContent.CreatedTime = note.CreatedTime;
            noteOrContent.UpdatedTime = note.UpdatedTime;
            noteOrContent.PublicTime  = note.PublicTime;
            //Files = files

            //------------- 删除API中不需要返回的内容
            noteOrContent.Content  = "";
            noteOrContent.Abstract = "";
            //	apiNote := info.NoteToApiNote(note, noteOrContent.Files)

            return(Json(noteOrContent, MyJsonConvert.GetLeanoteOptions()));
        }
Esempio n. 15
0
        /// <summary>
        /// 根据博客id 获取博客
        /// </summary>
        /// <param name="name"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public Dictionary <string, object> GetUserBlog(string name, int id)
        {
            BLL.BaseBLL <BlogInfo> blog = new BLL.BaseBLL <BlogInfo>();

            #region 优化前
            //var blogobj = blog.GetList(t => t.Id == id && t.Users.UserName == name).FirstOrDefault();

            ////这里看 能不能只查询一次
            //var blogNext = blog.GetList(t => t.Id > id && t.Users.UserName == name).OrderBy(t => t.Id).FirstOrDefault();
            //var blogLast = blog.GetList(t => t.Id < id && t.Users.UserName == name).OrderBy(t => t.Id).FirstOrDefault();
            #endregion

            //优化后 只查一次数据库
            //比如id 为3 那么 last取3,4  next取2,3
            var last = blog.GetList(t => t.Id >= id && t.User.UserName == name, isAsNoTracking: false, tableName: t => t.User).OrderBy(t => t.Id).Take(2);
            var next = blog.GetList(t => t.Id <= id && t.User.UserName == name, isAsNoTracking: false, tableName: t => t.User).OrderByDescending(t => t.Id).Take(2);
            //去重复合并
            var blogUnion = (from c in last select c).Union(from a in next select a).ToList();

            var blogNext = blogUnion.Where(t => t.Id > id).FirstOrDefault();
            var blogLast = blogUnion.Where(t => t.Id < id).FirstOrDefault();
            var blogobj  = blogUnion.Where(t => t.Id == id).FirstOrDefault();

            Dictionary <string, object> dic = new Dictionary <string, object>();
            dic.Add("blog", blogobj);
            dic.Add("blogNext", blogNext);
            dic.Add("blogLast", blogLast);
            dic.Add("contentBlogType", blogobj.Types == null ? new List <BlogType>() : blogobj.Types.ToList()); //当前博客所属的类型
            dic.Add("contentBlogTag", blogobj.Tags == null ? new List <BlogTag>() : blogobj.Tags.ToList());     //当前博客所有的tag标签

            //Description 网页描述
            var BlogContent = MyHtmlHelper.GetHtmlText(blogobj.Content);
            BlogContent = BlogContent.Length >= 300 ? BlogContent.Substring(0, 300) : BlogContent;
            dic.Add("blogConText", BlogContent);

            SetDic(dic, name);

            #region 保存 标记 此文已经阅读过
            var        BlogReadInfo = "BlogReadInfo";
            HttpCookie Cookie       = CookiesHelper.GetCookie(BlogReadInfo);
            if (null == Cookie)
            {
                Cookie = new HttpCookie(BlogReadInfo);
                Cookie.Values.Add(blogobj.Id.ToString(), "true");
                //设置Cookie过期时间
                Cookie.Expires = DateTime.Now.AddHours(24);//一天
                CookiesHelper.AddCookie(Cookie);
                //........................异步调用....................
                new SaveReadDelegate(SaveReadNum).BeginInvoke(blogobj, GetUserDistinguish(Request), null, null);
            }
            else
            {
                if (Cookie.Values[blogobj.Id.ToString()] == null || !Cookie.Values[blogobj.Id.ToString()].Equals("true"))
                {
                    CookiesHelper.SetCookie(BlogReadInfo, blogobj.Id.ToString(), "true");
                    //........................异步调用....................
                    new SaveReadDelegate(SaveReadNum).BeginInvoke(blogobj, GetUserDistinguish(Request), null, null);
                }
            }
            #endregion

            return(dic);
        }
Esempio n. 16
0
        /// <summary>
        /// 更新笔记 元数据
        /// </summary>
        /// <param name="apiNote"></param>
        /// <returns></returns>
        public static bool UpdateNote(ref ApiNote apiNote, long updateUser, long contentId, bool verifyUsn, bool verifyOwner,
                                      out string msg, out int afterUsn)
        {
            var noteId = MyConvert.HexToLong(apiNote.NoteId);

            afterUsn = 0;
            if (apiNote == null)
            {
                msg = "apiNote_is_null";
                return(false);
            }
            // var noteId = MyConvert.HexToLong(apiNote.NoteId);
            if (noteId == 0)
            {
                msg = "noteId_is_note_long_Number";
                return(false);
            }
            using (var db = new DataContext())
            {
                var result = db.Note.Where(b => b.NoteId == noteId && b.UserId == updateUser);
                if (result == null)
                {
                    msg = "inexistence";
                    return(false);
                }
                var note = result.FirstOrDefault();

                if (verifyUsn)
                {
                    if (note.Usn != apiNote.Usn)
                    {
                        msg = "Verify_Usn_Failure";
                        return(false);
                    }
                }
                if (verifyOwner)
                {
                    if (note.UserId != updateUser)
                    {
                        msg = "Verify_updateUser_Failure";
                        return(false);
                    }
                }
                if (apiNote.Desc != null)
                {
                    note.Desc = apiNote.Desc;
                }

                if (apiNote.Title != null)
                {
                    note.Title = apiNote.Title;
                }
                if (apiNote.IsTrash != null)
                {
                    note.IsTrash = apiNote.IsTrash.GetValueOrDefault();
                }
                if (apiNote.IsBlog != null)
                {
                    if (note.IsBlog == false && apiNote.IsBlog == true)
                    {
                        note.PublicTime = DateTime.Now;
                    }
                    note.IsBlog = apiNote.IsBlog.GetValueOrDefault(false);
                }
                if (apiNote.Tags != null)
                {
                    note.Tags = apiNote.Tags;
                    TagService.AddTags(note.UserId, note.Tags);
                    BlogService.ReCountBlogTags(note.UserId);
                }
                if (apiNote.NotebookId != null)
                {
                    var noteBookId = MyConvert.HexToLong(apiNote.NotebookId);
                    if (note.NotebookId == 0)
                    {
                        msg = "NotebookId_Is_Illegal";
                        return(false);
                    }
                    if (note.NotebookId != noteBookId)
                    {
                        // 如果修改了notebookId, 则更新notebookId'count
                        // 两方的notebook也要修改
                        NotebookService.ReCountNotebookNumberNotes(note.NotebookId);
                        NotebookService.ReCountNotebookNumberNotes(noteBookId);
                        note.NotebookId = noteBookId;
                    }
                }
                if (apiNote.Content != null)
                {
                    note.ContentId = contentId;
                    if (apiNote.Abstract == null)
                    {
                        if (apiNote.IsMarkdown.GetValueOrDefault(note.IsMarkdown))
                        {
                            note.Desc = MyHtmlHelper.SubMarkDownToRaw(apiNote.Content, 200);
                        }
                        else
                        {
                            note.Desc = MyHtmlHelper.SubHTMLToRaw(apiNote.Content, 200);
                        }
                        //  note.Desc = MyHtmlHelper.SubStringHTMLToRaw(apiNote.Content, 200);
                    }
                    else
                    {
                        note.Desc = MyHtmlHelper.SubHTMLToRaw(apiNote.Abstract, 200);
                        //note.Desc = MyHtmlHelper.SubStringHTMLToRaw(apiNote.Abstract, 200);
                    }
                }
                if (apiNote.UpdatedTime != null)
                {
                    note.UpdatedTime = Tools.FixUrlTime(apiNote.UpdatedTime);
                }
                else
                {
                    note.UpdatedTime = DateTime.Now;
                }
                if (note.IsBlog && note.HasSelfDefined)
                {
                    note.ImgSrc = null;
                    note.Desc   = null;
                }
                if (apiNote.IsTrash != null)
                {
                    note.IsTrash = apiNote.IsTrash.GetValueOrDefault(false);
                    NotebookService.ReCountNotebookNumberNotes(note.NotebookId);
                }
                if (apiNote.IsMarkdown != null)
                {
                    note.IsMarkdown = apiNote.IsMarkdown.GetValueOrDefault();
                }
                note.UpdatedUserId = MyConvert.HexToLong(apiNote.UserId);
                //更新用户元数据乐观锁
                afterUsn = UserService.IncrUsn(note.UserId);
                //更新笔记元数据乐观锁
                note.Usn = afterUsn;
                db.SaveChanges();
                msg = "success";
                return(true);
            }
        }