Ejemplo n.º 1
0
        /// <summary>
        /// 自定义 特殊页面 公共方法
        /// </summary>
        /// <param name="str">BlogTitle名字</param>
        /// <param name="pageName">存在MyPageId的KEY名</param>
        private void Forum(string str, string pageName)
        {
            #region 检测是否存在 admin 用户
            BLL.BaseBLL <BlogUser> userbll = new BLL.BaseBLL <BlogUser>();
            if (adminuserid <= 0)
            {
                var user = userbll.GetList(t => t.UserName == admin).FirstOrDefault();
                if (null == user)
                {
                    var usertemp = new BlogUser()
                    {
                        UserName     = admin,
                        UserPass     = "******".MD5().MD5(),
                        IsDelte      = false,
                        IsLock       = false,
                        UserNickname = "",
                        UserMail     = "无效",
                        BlogUserInfo = new BlogUserInfo()
                    };
                    userbll.Insert(usertemp);
                    userbll.save(false);
                    adminuserid = usertemp.Id;
                }
                else
                {
                    adminuserid = user.Id;
                }
            }

            #endregion

            #region 是否存在 自定义 特殊页面 (返回 blogid)
            if (MyPageId[pageName] == 0)
            {
                BLL.BaseBLL <BlogInfo> blogbll = new BLL.BaseBLL <BlogInfo>();
                var blog = blogbll.GetList(t => t.Title == str).FirstOrDefault();
                if (null == blog)
                {
                    var bloguser = userbll.GetList(t => t.Id == adminuserid, isAsNoTracking: false).FirstOrDefault();
                    var blogtemp = new BlogInfo()
                    {
                        Id = 0,
                        //BlogUser = new BlogUser() { Id = adminuserid },
                        User    = bloguser,
                        IsDelte = false,
                        Title   = str
                    };
                    blogbll.Insert(blogtemp);
                    blogbll.save();
                    // CacheData.GetAllUserInfo(true);//更新缓存
                    MyPageId[pageName] = blogtemp.Id;
                }
                else
                {
                    MyPageId[pageName] = blog.Id;
                }
            }
            #endregion
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 自定义 特殊页面 公共方法 (弃用)
        /// </summary>
        /// <param name="str"></param>
        /// <param name="messid"></param>
        private void Forum(string str, ref int messid)
        {
            #region 检测是否存在 admin 用户

            if (adminuserid <= 0)
            {
                BLL.BaseBLL <BlogUser> userbll = new BLL.BaseBLL <BlogUser>();
                var user = userbll.GetList(t => t.UserName == admin).FirstOrDefault();
                if (null == user)
                {
                    var usertemp = new BlogUser()
                    {
                        UserName     = admin,
                        UserPass     = "******".MD5().MD5(),
                        IsDelte      = false,
                        IsLock       = false,
                        UserNickname = "",
                        BlogUserInfo = new BlogUserInfo()
                    };
                    userbll.Insert(usertemp);
                    userbll.save(false);
                    adminuserid = usertemp.Id;
                }
                else
                {
                    adminuserid = user.Id;
                }
            }

            #endregion

            #region 是否存在 自定义 特殊页面 (返回 blogid)
            if (messid == 0)
            {
                BLL.BaseBLL <BlogInfo> blogbll = new BLL.BaseBLL <BlogInfo>();
                var blog = blogbll.GetList(t => t.Title == str).FirstOrDefault();
                if (null == blog)
                {
                    var blogtemp = new BlogInfo()
                    {
                        Id   = 0,
                        User = new BlogUser()
                        {
                            Id = adminuserid
                        },
                        IsDelte = false,
                        Title   = str
                    };
                    blogbll.Insert(blogtemp);
                    blogbll.save(false);
                    //GetDataHelper.GetAllUserInfo(true);//更新缓存
                    messid = blogtemp.Id;
                }
                else
                {
                    messid = blog.Id;
                }
            }
            #endregion
        }
Ejemplo n.º 3
0
        /// <summary>
        /// (已弃用)
        /// </summary>
        /// <param name="idex">页码</param>
        /// <param name="sizePage">页容量</param>
        /// <param name="ContentLength">内容截取长度</param>
        /// <returns></returns>
        public object Get(int idex, int sizePage, int ContentLength)
        {
            int total;

            BLL.BaseBLL <BlogInfo> blog = new BLL.BaseBLL <BlogInfo>();
            var bloglist = blog.GetList(idex, sizePage, out total, t => t.IsShowHome == true, false, t => t.BlogCreateTime, false, tableName: t => t.User)//
                           .ToList()
                           .Select(t => new BlogInfo()
            {
                Id             = t.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("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);
        }
Ejemplo n.º 4
0
 private int GetTagId(string tagname, string userName)
 {
     BLL.BaseBLL <BlogTag> blogtag = new BLL.BaseBLL <BlogTag>();
     try
     {
         var blogtagmode = blogtag.GetList(t => t.TagName == tagname);
         if (blogtagmode.Count() >= 1)
         {
             return(blogtagmode.FirstOrDefault().Id);
         }
         else
         {
             var tmepUserid = GetUserId(userName);
             var user       = new BLL.BaseBLL <BlogUser>().GetList(t => t.Id == tmepUserid, isAsNoTracking: false).FirstOrDefault();
             blogtag.Insert(new BlogTag()
             {
                 TagName  = tagname,
                 IsDelte  = false,
                 BlogUser = user// new BlogUser { Id = GetUserId(userName), IsLock = false, BlogUserInfo = new BlogUserInfo() },
             });
             blogtag.save();
             return(GetTagId(tagname, userName));
         }
     }
     catch (Exception ex)
     {
         throw;
         return(-1);
     }
 }
Ejemplo n.º 5
0
        private void SaveReadNum(BlogInfo blogobj, string md5)
        {
            LogSave.TrackLogSave(GetUserDistinguish(Request, false), "ReadBlogLog");
            var isup = true;

            BLL.BaseBLL <BlogInfo> blogbll = new BLL.BaseBLL <BlogInfo>();
            var blogtemp = blogbll.GetList(t => t.Id == blogobj.Id, isAsNoTracking: false).FirstOrDefault();

            if (blogtemp.ReadNum == null)
            {
                blogtemp.ReadNum = 1;
            }
            else if (!IsRead(blogtemp, md5))
            {
                blogtemp.ReadNum++;
            }
            else
            {
                isup = false;
            }
            if (isup)
            {
                blogbll.save();
            }
        }
Ejemplo n.º 6
0
        private void MyBegin()
        {
            try
            {
                //设置日志存放路径
                LogConfig.logFilePath = HttpContext.Current.Server.MapPath("~/") + @"\Log\";
                Blogs.Helper.FileHelper.defaultpath = HttpContext.Current.Server.MapPath("~/");

                BLL.BaseBLL <BlogUser> userbll = new BLL.BaseBLL <BlogUser>();
                var isbegin = userbll.GetList(t => true).Count() > 0;
                if (!isbegin)
                {
                    var user = new BlogUser()
                    {
                        UserName     = "******",
                        UserPass     = "******",
                        IsDelte      = false,
                        IsLock       = false,
                        UserMail     = "无效",
                        CreationTime = DateTime.Now,
                        BlogUserInfo = new BlogUserInfo()
                    };
                    userbll.Insert(user);
                    userbll.save(false);
                }

                DemoController.GetData();
            }
            catch (Exception) { }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 检查 这个 url地址 是否被添加过
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private bool IsAreBlog(string url)
        {
            BLL.BaseBLL <BlogInfo> blog = new BLL.BaseBLL <BlogInfo>();
            var blogs = blog.GetList(t => t.Url == url);

            return(blogs.Count() >= 1);
        }
Ejemplo n.º 8
0
        [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);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 根据博客ID 取评论内容
        /// </summary>
        /// <param name="blogId">博客id</param>
        /// <param name="index">页码</param>
        /// <param name="sizePage">页容量</param>
        /// <param name="order">升序:true 降序:false</param>
        /// <returns></returns>
        public object GetComment(int blogId, int index, int sizePage, bool order)
        {
            int total;

            BLL.BaseBLL <BlogComment> comment = new BLL.BaseBLL <BlogComment>();
            var commentList = comment.GetList(index, sizePage, out total, t => t.BlogInfo.Id == blogId, false, t => t.Id, order)
                              .ToList().Select(t => new BlogComment()
            {
            });
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("CommentList", commentList);
            dic.Add("Total", total);//总页数
            return(dic);
        }
Ejemplo n.º 10
0
        public ActionResult Index(int?id)
        {
            //
            int total;

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

            BLL.BaseBLL <BlogInfo> blog = new BLL.BaseBLL <BlogInfo>();
            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.Title,
                BlogContent    = t.Content,
                UserName       = t.User.UserName,
                UserNickname   = t.User.UserNickname,
                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,
                User           = new BlogUser()
                {
                    UserName     = t.UserName,
                    UserNickname = t.UserNickname
                },
                ReadNum    = t.BlogReadNum,
                CommentNum = t.BlogCommentNum
            }).ToList();

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

            dic.Add("blog", bloglist);
            dic.Add("users", GetDataHelper.GetAllUser().Where(t => t.IsLock == false).ToList());
            dic.Add("SessionUser", BLL.Common.BLLSession.UserInfoSessioin);
            dic.Add("total", total);
            return(View(dic));
        }
Ejemplo n.º 11
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());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取博客  详细 信息
        /// </summary>
        /// <param name="blogId">博客ID</param>
        /// <returns></returns>
        public object GetBlogInfo(int blogId)
        {
            BLL.BaseBLL <BlogInfo> blog = new BLL.BaseBLL <BlogInfo>();
            var blogobj = blog.GetList(t => t.Id == blogId).FirstOrDefault();

            if (blogobj == null)
            {
                return new { mes = "您输入的博客ID不存在" }
            }
            ;
            Dictionary <string, object> dic = new Dictionary <string, object>();

            dic.Add("Blog", new BlogInfo()
            {
                IsDelte = blogobj.IsDelte,
                ReadNum = blogobj.ReadNum,
                Tags    = blogobj.Tags,
                Title   = blogobj.Title,
                Content = blogobj.Content
            });
            return(dic);
        }
Ejemplo n.º 13
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));
        }
Ejemplo n.º 14
0
 /// <summary>
 /// 获取用户所有文章标签
 /// </summary>
 /// <returns></returns>
 public static IQueryable <BlogTag> GetAllTag(string name)
 {
     BLL.BaseBLL <BlogTag> tag = new BLL.BaseBLL <BlogTag>();
     return(tag.GetList(t => t.BlogUser.UserName == name));
 }
        /// <summary>
        /// 激活 (实际上是验证激活码后  修改用户信息:包括是否激活IsLock、邮箱地址、密码 )
        /// </summary>
        /// <returns></returns>
        public string Activate()
        {
            var json = new JSData();

            #region 1.判断是否从正常途径访问此页面 如果是的话 默认存在 Session[tempUserinfo]  2.如果是已经登录状态则直接无视 跳转

            if (null == Session[tempUserinfo])
            {
                json.State = EnumState.失败;//json.Messg = "请您通过正常途径访问激活页面~";
                json.JSurl = "/";
                return(json.ToJson());
            }
            if (BLLSession.UserInfoSessioin != null && !BLLSession.UserInfoSessioin.IsLock)
            {
                json.State = EnumState.失败; //json.Messg = "您都已经登录的还想获取激活码?别玩了~";
                json.JSurl = "/";
                return(json.ToJson());
            }
            #endregion

            var tempuser = ((BlogUser)HttpContext.Current.Session[tempUserinfo]);
            var activate = HttpContext.Current.Request.Form["txt_activate"];//激活码

            #region 2.验证激活码  (更新缓存 发送通知邮件 清空无用session)
            if (activate.Trim() == Session[jihuoma].ToString().Trim()) //验证激活码
            {
                BLL.BaseBLL <BlogUser> user = new BLL.BaseBLL <BlogUser>();
                var objuser          = user.GetList(t => t.Id == tempuser.Id, isAsNoTracking: false).FirstOrDefault();
                var isEffectiveEmail = !string.IsNullOrEmpty(objuser.UserMail) && objuser.UserMail != "无效";//是否是有效邮箱(迁移用户是无效邮箱)
                if (null != objuser)
                {
                    objuser.IsLock   = false;
                    objuser.UserPass = isEffectiveEmail ? tempuser.UserPass.MD5().MD5() : defaulPass.MD5().MD5();
                    objuser.UserMail = tempuser.UserMail;
                    if (objuser.BlogUserInfo == null)
                    {
                        objuser.BlogUserInfo = new BlogUserInfo()
                        {
                            BlogUpNum = 0
                        };
                    }
                }
                user.save();
                #region bug 记录
                //BlogUsers objuser = new BlogUsers();
                //objuser.Id = id;
                //objuser.IsLock = false;
                // user.Up(objuser, "IsLock");  //这个方法 正常情况用没问题,如果先添加   然后修改就有问题  (不能用)
                #endregion
                bool islock = GetDataHelper.GetAllUser().Where(t => t.Id == tempuser.Id).FirstOrDefault().IsLock;
                if (!islock)
                {
                    #region 发送邮件 告知 激活成功

                    var tempSessionUser      = (BlogUser)Session[tempUserinfo];
                    var nickName             = string.IsNullOrEmpty(tempSessionUser.UserNickname) ? tempSessionUser.UserName : tempSessionUser.UserName;
                    Helper.EmailHelper email = new Helper.EmailHelper()
                    {
                        mailPwd     = s_mailPwd,
                        host        = s_host,
                        mailFrom    = s_mailFrom,
                        mailSubject = "欢迎您注册 嗨-博客",
                        mailBody    = EmailHelper.tempBody(nickName, "欢迎注册 嗨-博客",
                                                           "您注册的的帐号:" + objuser.UserName + "   密码是:" + (isEffectiveEmail ? tempuser.UserPass : defaulPass), "请您妥善保管~"),
                        mailToArray = new string[] { tempSessionUser.UserMail }
                    };

                    try
                    {
                        email.Send(t =>
                        {
                            LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + tempSessionUser.UserMail + "\r\nBody:" + t.Body, "发送成功的邮件");
                        },
                                   t =>
                        {
                            LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + tempSessionUser.UserMail + "\r\nBody:" + t.Body, "发送失败的邮件");
                        }
                                   );
                    }
                    catch (Exception)
                    { }

                    #endregion

                    Session[jihuoma]      = null;
                    Session[tempUserinfo] = null;

                    BLLSession.UserInfoSessioin = objuser;
                    return(new JSData()
                    {
                        Messg = "恭喜您~激活成功~",
                        State = EnumState.正常重定向,
                        JSurl = "/"
                    }.ToJson());
                }
                else
                {
                    return(new JSData()
                    {
                        Messg = "激活失败,请联系管理员~",
                        State = EnumState.失败
                    }.ToJson());
                }
            }
            #endregion

            return(new JSData()
            {
                Messg = "您输入的激活码错误,你可以重新激活~",
                State = EnumState.失败
            }.ToJson());
        }
Ejemplo n.º 16
0
 /// <summary>
 /// 获取所有用户信息
 /// </summary>
 /// <returns></returns>
 public static IQueryable <BlogUser> GetAllUser()
 {
     BLL.BaseBLL <BlogUser> user = new BLL.BaseBLL <BlogUser>();
     return(user.GetList(t => true));
 }
        public string WriteContent()
        {
            #region 评论前先检查是否已经登录
            var AnonymousName = string.Empty;//匿名登录
            if (Request.Form.AllKeys.Contains("AnonymousName") && !string.IsNullOrEmpty(Request.Form["AnonymousName"]))
            {
                AnonymousName = Request.Form["AnonymousName"];
            }
            else if (null == BLLSession.UserInfoSessioin)
            {
                return(new JSData()
                {
                    Messg = "您还未登录~",
                    State = EnumState.异常或Session超时
                }.ToJson());
            }
            var sessionUser = BLLSession.UserInfoSessioin;

            //if (BLLSession.UserInfoSessioin.IsLock)
            //{
            //    return new JSData()
            //    {
            //        Messg = "您的账户已经被锁定,请联系管理员~",
            //        State = EnumState.失败
            //    }.ToJson();
            //}
            #endregion

            var BlogId      = int.Parse(Request.Form["BlogId"]);
            var UserId      = sessionUser.Id == 0 ? 1 : sessionUser.Id; //int.Parse(Request.Form["UserId"]);
            var CommentID   = int.Parse(Request.Form["CommentID"]);
            var Content     = Request.Form["Content"];
            var ReplyUserID = int.Parse(Request.Form["ReplyUser"]);

            if (Content.Length >= 1000)
            {
                return(new JSData()
                {
                    State = EnumState.失败
                }.ToJson());
            }

            var ReplyUserName = string.Empty;
            var User          = GetDataHelper.GetAllUser().Where(t => t.Id == ReplyUserID).FirstOrDefault();

            if (null != User)
            {
                ReplyUserName = string.IsNullOrEmpty(User.UserNickname) ? User.UserName : User.UserNickname;
            }

            BLL.BaseBLL <BlogComment> comment = new BLL.BaseBLL <BlogComment>();

            var user     = new BLL.BaseBLL <BlogUser>().GetList(t => t.Id == UserId, isAsNoTracking: false).FirstOrDefault();
            var bloginfo = new BLL.BaseBLL <BlogInfo>().GetList(t => t.Id == BlogId, isAsNoTracking: false).FirstOrDefault();
            comment.Insert(new BlogComment()
            {
                BlogUser      = user,
                BlogInfo      = bloginfo,
                Content       = Content,
                CommentID     = CommentID,
                ReplyUserID   = ReplyUserID,
                ReplyUserName = ReplyUserName,
                IsInitial     = CommentID == -1,
                AnonymousName = AnonymousName
            });

            BLL.BaseBLL <BlogInfo> blogbll = new BLL.BaseBLL <BlogInfo>();
            var blogmode = blogbll.GetList(t => t.Id == BlogId, isAsNoTracking: false).FirstOrDefault();
            if (null == blogmode.CommentNum)
            {
                blogmode.CommentNum = comment.GetList(t => t.BlogInfo.Id == BlogId).Count() + 1;
            }
            else
            {
                blogmode.CommentNum++;
            }

            blogbll.Up(blogmode);
            blogbll.save();

            comment.save();

            #region 评论邮件通知

            var         sessionName = string.IsNullOrEmpty(sessionUser.UserNickname) ? sessionUser.UserName : sessionUser.UserNickname;
            var         tempUser    = (User ?? blogmode.User);
            var         nickName    = string.IsNullOrEmpty(tempUser.UserNickname) ? tempUser.UserName : tempUser.UserNickname;
            var         blogUrl     = "http://" + Request.Url.Authority + "/" + blogmode.User.UserName + "/" + blogmode.Id + ".html";
            EmailHelper email       = new EmailHelper()
            {
                mailPwd     = s_mailPwd,
                host        = s_host,
                mailFrom    = s_mailFrom,
                mailSubject = "嗨-博客 消息提醒~",
                mailBody    = EmailHelper.tempBody(nickName, sessionName + "回复您:<br/>" + Content, "<a href='" + blogUrl + "' target='_blank'>" + blogUrl + "</a>", isShow: false),
                mailToArray = new string[] { tempUser.UserMail }
            };
            try
            {
                email.Send(t =>
                {
                    LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + User.UserMail + "\r\nBody:" + t.Body, "发送成功的邮件");
                },
                           t =>
                {
                    LogSave.TrackLogSave("IP:" + RequestHelper.GetIp() + "\r\nToMail:" + User.UserMail + "\r\nBody:" + t.Body, "发送失败的邮件");
                }
                           );
            }
            catch (Exception)
            { }
            #endregion

            return(new JSData()
            {
                //这里发表成功    就不提示了。
                State = EnumState.成功
            }.ToJson());
        }
Ejemplo n.º 18
0
 public static IQueryable <BlogTag> GetAllTag(int id)
 {
     BLL.BaseBLL <BlogTag> tag = new BLL.BaseBLL <BlogTag>();
     return(tag.GetList(t => t.BlogUser.Id == id));
 }
Ejemplo n.º 19
0
 public static IQueryable <BlogTag> GetAllTag()
 {
     BLL.BaseBLL <BlogTag> tag = new BLL.BaseBLL <BlogTag>();
     return(tag.GetList(t => true));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// 根据用户名  获取用户信息
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public static BlogUser GetUser(string name)
 {
     BLL.BaseBLL <BlogUser> user = new BLL.BaseBLL <BlogUser>();
     return(user.GetList(t => t.UserName == name).FirstOrDefault());
 }
Ejemplo n.º 21
0
 public static IQueryable <BlogUser> GetAllUser <T>(Expression <Func <BlogUser, T> > TTbName, bool isAsNoTracking = true)
 {
     BLL.BaseBLL <BlogUser> user = new BLL.BaseBLL <BlogUser>();
     return(user.GetList(t => true, tableName: TTbName, isAsNoTracking: isAsNoTracking));
 }
Ejemplo n.º 22
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);
        }
Ejemplo n.º 23
0
 public static IQueryable <BlogUserInfo> GetUserInfo(int id)
 {
     BLL.BaseBLL <BlogUserInfo> userinfo = new BLL.BaseBLL <BlogUserInfo>();
     return(userinfo.GetList(t => t.BlogUser.Id == id));
 }
        public string ThirdLoginCallback(string code, string loginType = "qq")
        {
            //第三步:获取开放平台授权令牌
            IOAuthClient oauthClient  = GetOAuthClient(loginType);
            AuthToken    accessToken  = oauthClient.GetAccessTokenByAuthorizationCode(code);
            dynamic      oauthProfile = oauthClient.User.GetUserInfo();

            if (accessToken != null && !string.IsNullOrEmpty(oauthClient.Token.User.OAuthId))
            {
                BLL.BaseBLL <BlogUserInfo> userInfo = new BLL.BaseBLL <BlogUserInfo>();
                var userInfoMode = userInfo.GetList(t => t.OAuthId == oauthClient.Token.User.OAuthId && t.OAuthName == loginType).FirstOrDefault();
                if (null == userInfoMode)
                {
                    BLL.BaseBLL <BlogUser> user = new BLL.BaseBLL <BlogUser>();
                    user.Insert(new BlogUser()
                    {
                        IsLock       = true,
                        UserMail     = "无效",
                        UserName     = oauthClient.Token.User.OAuthId + "_" + loginType,
                        UserNickname = oauthClient.Token.User.Nickname,
                        UserPass     = "******".MD5().MD5(),
                        IsDelte      = false,
                        BlogUserInfo = new BlogUserInfo()
                        {
                            OAuthId   = oauthClient.Token.User.OAuthId,
                            OAuthName = loginType,
                            BlogUpNum = 0,
                            IsDelte   = false
                        }
                    });
                    user.save(false);
                    userInfoMode = userInfo.GetList(t => t.OAuthId == oauthClient.Token.User.OAuthId && t.OAuthName == loginType).FirstOrDefault();
                    //BLL.Common.CacheData.GetAllUserInfo(true);
                }

                #region 设置cookie(等于设置了session,因为读session的时候会检测cookie)
                var        userTemp = userInfoMode.BlogUser;
                HttpCookie Cookie   = CookiesHelper.GetCookie("userInfo");
                if (Cookie == null)
                {
                    Cookie = new HttpCookie("userInfo");
                    Cookie.Values.Add("userName", userTemp.UserName);
                    Cookie.Values.Add("userPass", "pass");
                    //设置Cookie过期时间
                    Cookie.Expires = DateTime.Now.AddDays(365);
                    CookiesHelper.AddCookie(Cookie);
                }
                else
                {
                    if (!Cookie.Values["userName"].Equals(userTemp.UserName))
                    {
                        CookiesHelper.SetCookie("userInfo", "userName", userTemp.UserName);
                    }
                    if (!Cookie.Values["userPass"].Equals("pass"))
                    {
                        CookiesHelper.SetCookie("userInfo", "userPass", "pass");
                    }
                }
                //BLLSession.UserInfoSessioin = userInfoMode.BlogUser;
                #endregion

                return("ok");
            }
            return("no");
        }