Esempio n. 1
0
        public bool UpdatePostComment(BlogCommentDto postCommentDto)
        {
            bool result = true;

            try
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    connection.Open();

                    string     sqlProcedure = "UpdatePostComment";
                    SqlCommand command      = new SqlCommand(sqlProcedure, connection);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("@Id", postCommentDto.Id);
                    command.Parameters.AddWithValue("@Comment", postCommentDto.Comment);
                    command.Parameters.AddWithValue("@LastUpdate", postCommentDto.LastUpdate);

                    command.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
                result = false;
            }

            return(result);
        }
Esempio n. 2
0
        public async Task <IActionResult> AddBlogCommnet(BlogCommentDto blogCommentDto)
        {
            BaseDataResultDto baseDataResultDto = new BaseDataResultDto();

            baseDataResultDto.Code = 1;
            if (!ModelState.IsValid)
            {
                baseDataResultDto.Code = 1;
                baseDataResultDto.Msg  = "评论的格式不对";
            }
            else
            {
                //获取登录用户的userId
                var claim = GetClaim(HttpContext.User.Claims, ClaimTypes.Sid);
                if (claim != null)
                {
                    blogCommentDto.PostId = int.Parse(claim.Value);
                }

                if (await _blogCommentService.AddBlogComment(blogCommentDto))
                {
                    baseDataResultDto.Code = 0;
                    baseDataResultDto.Msg  = "添加评论成功";

                    await _blogService.UpdateCommentNum(blogCommentDto.BlogId, 1);
                }
            }
            return(Json(baseDataResultDto));
        }
Esempio n. 3
0
        /// <summary>
        /// 创建评论回复界面
        /// </summary>
        /// <param name="blogCommentDto"></param>
        /// <returns></returns>
        private string CreateCommentOperator(BlogCommentDto blogCommentDto, string userName)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("<div class='comment_operator'>");
            //stringBuilder.AppendLine($" <span class='comment_reply'>回复</span>");
            stringBuilder.AppendLine("  <div class='replyBox' style='display: none'>");
            //stringBuilder.AppendLine($"   <span id = 'repalyId{blogCommentDto.BCId}' class='commentId' style='display: none'>{blogCommentDto.BCId}</span>");
            stringBuilder.AppendLine("    <div class='comment_replyer'>");
            if (string.IsNullOrEmpty(userName))
            {
                stringBuilder.AppendLine("     昵称:<input  class='repalyTitle' type='text' value='匿名用户' />");
            }
            else
            {
                stringBuilder.AppendLine($"     昵称:<input  class='repalyTitle' type='text' readonly='readonly' value='{userName}' />");
            }
            stringBuilder.AppendLine("    </div>");
            stringBuilder.AppendLine("    <div class='comment_replycontent'>");
            stringBuilder.AppendLine("    <textarea  maxlength='800' cols='80' rows='5' class='repalyContent' ></textarea>");
            stringBuilder.AppendLine("    </div>");
            stringBuilder.AppendLine("    <div class='comment_replybutton'>");
            stringBuilder.AppendLine($"    <input  class='repalyButton' refid='{blogCommentDto.BCId}' type='button' value='发表' /><input  class='closeButton' refid='{blogCommentDto.BCId}' type='button' value='关闭' />");
            stringBuilder.AppendLine("    </div>");
            stringBuilder.AppendLine(" </div>");
            stringBuilder.AppendLine("</div>");

            return(stringBuilder.ToString());
        }
Esempio n. 4
0
        public BlogCommentDto GetPostCommentById(int id)
        {
            var postComment = new BlogCommentDto();

            try
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    connection.Open();

                    string     sqlProcedure = "GetPostCommentById";
                    SqlCommand command      = new SqlCommand(sqlProcedure, connection);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("@Id", id);

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            postComment = MapToBlogCommentDto(reader);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }

            return(postComment);
        }
Esempio n. 5
0
        /// <summary>
        /// 添加博客评论
        /// </summary>
        /// <param name="blogDto"></param>
        /// <returns></returns>
        public async Task <bool> AddBlogComment(BlogCommentDto blogCommentDto)
        {
            string sql = "insert into `blogcomment`(BlogId,ReferenceId,PostId,PostName,Content,PostDate) VALUES(@BlogId,@ReferenceId,@PostId,@PostName,@Content,@PostDate)";

            using (var connect = CreateConnection())
            {
                return(await connect.ExecuteAsync(sql, new { BlogId = blogCommentDto.BlogId, ReferenceId = blogCommentDto.ReferenceId, PostId = blogCommentDto.PostId, PostName = blogCommentDto.PostName, Content = blogCommentDto.Content, PostDate = DateTime.Now }) > 0);
            }
        }
Esempio n. 6
0
 public void copy(BlogComment blogComment, BlogCommentDto dto)
 {
     blogComment.blog_comment_id = dto.blog_comment_id;
     blogComment.blog_id         = dto.blog_id;
     blogComment.comments        = dto.comments;
     blogComment.comment_by      = dto.comment_by;
     blogComment.comment_date    = dto.comment_date;
     blogComment.email           = dto.email;
 }
Esempio n. 7
0
        // 向quoteList中添加 符合条件的Comment
        private void AddComment(List <BlogCommentDto> list, List <BlogCommentDto> quoteList, BlogCommentDto blogCommentDto)
        {
            BlogCommentDto fbcd = list.FirstOrDefault(p => p.BCId == blogCommentDto.ReferenceId);

            if (fbcd != null)
            {
                quoteList.Add(fbcd);
                AddComment(list, quoteList, fbcd); // 递归调用,只要ReferenceId不为零,就加入到引用评论列表
            }
        }
Esempio n. 8
0
        public void CannotSaveNewCommentWithNoEmail()
        {
            var comment = new BlogCommentDto
            {
                BlogId  = 1,
                Name    = "Matt",
                Title   = "This is a blog Title",
                Comment = "This is the comment"
            };
            var result = _blogRepo.SaveComments(comment);

            result.Status.ShouldBe(false);
        }
Esempio n. 9
0
        private BlogCommentDto MapToBlogCommentDto(SqlDataReader reader)
        {
            var blogComment = new BlogCommentDto();

            blogComment.Id         = Convert.ToInt32(reader["Id"]);
            blogComment.BlogId     = Convert.ToInt32(reader["BlogId"]);
            blogComment.UserName   = reader["UserName"].ToString();
            blogComment.Comment    = reader["Comment"].ToString();
            blogComment.LastUpdate = Convert.ToDateTime(reader["LastUpdate"]);
            blogComment.Created    = Convert.ToDateTime(reader["Created"]);

            return(blogComment);
        }
        public static BlogCommentViewModel MapTo(BlogCommentDto blogCommentDto)
        {
            var blogCommentViewModel = new BlogCommentViewModel();

            blogCommentViewModel.Id         = blogCommentDto.Id;
            blogCommentViewModel.UserName   = blogCommentDto.UserName;
            blogCommentViewModel.BlogId     = blogCommentDto.BlogId;
            blogCommentViewModel.Comment    = blogCommentDto.Comment;
            blogCommentViewModel.LastUpdate = blogCommentDto.LastUpdate;
            blogCommentViewModel.Created    = blogCommentDto.Created;

            return(blogCommentViewModel);
        }
        public static BlogCommentDto MapFrom(BlogCommentViewModel blogCommentViewModel)
        {
            var blogCommentDto = new BlogCommentDto();

            blogCommentDto.Id         = blogCommentViewModel.Id;
            blogCommentDto.UserName   = blogCommentViewModel.UserName;
            blogCommentDto.BlogId     = blogCommentViewModel.BlogId;
            blogCommentDto.Comment    = blogCommentViewModel.Comment;
            blogCommentDto.LastUpdate = blogCommentViewModel.LastUpdate;
            blogCommentDto.Created    = blogCommentViewModel.Created;

            return(blogCommentDto);
        }
Esempio n. 12
0
        public void CanSaveNewComment()
        {
            var comment = new BlogCommentDto
            {
                BlogId  = 1,
                Email   = "*****@*****.**",
                Name    = "Matt",
                Title   = "This is a blog Title",
                Comment = "This is the comment"
            };
            var result = _blogRepo.SaveComments(comment);

            result.Status.ShouldBe(true);
        }
Esempio n. 13
0
        public IActionResult blogCommentEdit(long blog_comment_id)
        {
            try
            {
                var            blogComment    = _blogCommentRepo.getById(blog_comment_id);
                BlogCommentDto blogCommentDto = _mapper.Map <BlogCommentDto>(blogComment);

                return(View(blogCommentDto));
            }
            catch (Exception ex)
            {
                AlertHelper.setMessage(this, ex.Message, messageType.error);
                return(RedirectToAction("index"));
            }
        }
Esempio n. 14
0
 public IActionResult blogCommentEdit(BlogCommentDto blog_comment_dto)
 {
     try
     {
         if (ModelState.IsValid)
         {
             _blogCommentService.update(blog_comment_dto);
             AlertHelper.setMessage(this, "Blog Comment updated successfully.");
             return(RedirectToAction("index"));
         }
     }
     catch (Exception ex)
     {
         AlertHelper.setMessage(this, ex.Message, messageType.error);
     }
     return(View(blog_comment_dto));
 }
 public void save(BlogCommentDto blogcomment_dto)
 {
     try
     {
         using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required))
         {
             BlogComment blogComment = new BlogComment();
             _blogCommentMaker.copy(blogComment, blogcomment_dto);
             _blogCommentRepo.insert(blogComment);
             tx.Complete();
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 16
0
        public ActionResult SaveComment(BlogCommentDto blogComment)
        {
            var result = new OperationStatus();

            if (ModelState.IsValid)
            {
                result = _blogRepository.SaveComments(blogComment);
                var blog        = _blogRepository.GetBlog(blogComment.BlogId);
                var partialView = this.RenderPartialViewToString("_BlogCommentListPartial", blog.BlogComments);
                result.RenderedPartialViewUpdate = partialView;
            }
            else
            {
                result.Message = "Failed to save comment";
            }

            return(Json(result));
        }
        public IActionResult sendBlog(BlogCommentDto dto)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var slug = _blogRepo.getById(dto.blog_id).slug;
                    _blogCommentService.save(dto);
                    AlertHelper.setMessage(this, "Comments saved successfully.", messageType.success);

                    return(RedirectToAction("detail", "blog", new { @id = slug }));
                }
                catch (Exception ex)
                {
                    TempData["message"] = ex.Message;
                    return(RedirectToAction("detail"));
                }
            }
            return(View(dto));
        }
Esempio n. 18
0
        //private string CreateComment_Detail(BlogCommentDto blogCommentDto, string userName, string reference)
        //{
        //    StringBuilder stringBuilder = new StringBuilder();
        //    stringBuilder.AppendLine("<div class='comment_detail'>");
        //    stringBuilder.AppendLine($"  <div class='comment_title'>{blogCommentDto.PostName}<span class='comment_date'>发表于:{blogCommentDto.PostDate}</span></div>");
        //    if (string.IsNullOrEmpty(reference))
        //    {
        //        stringBuilder.AppendLine($"  <div class='comment_content'>{blogCommentDto.Content}</div>");
        //    }
        //    else
        //    {
        //        stringBuilder.AppendLine($"  <div class='comment_content'>{reference}</div>");
        //        stringBuilder.AppendLine($"  <div class='comment_content'>{blogCommentDto.Content}</div>");
        //    }
        //    //回复界面
        //    stringBuilder.AppendLine(CreateCommentOperator(blogCommentDto, userName));
        //    stringBuilder.AppendLine("</div>");
        //    return stringBuilder.ToString();
        //}

        ///// <summary>
        ///// 创建评论回复界面
        ///// </summary>
        ///// <param name="blogCommentDto"></param>
        ///// <returns></returns>
        //private string CreateCommentOperator(BlogCommentDto blogCommentDto, string userName)
        //{
        //    StringBuilder stringBuilder = new StringBuilder();
        //    stringBuilder.AppendLine("<div class='comment_operator'>");
        //    stringBuilder.AppendLine($" <span class='comment_reply' id='comment_reply{blogCommentDto.BCId}' commentid='{blogCommentDto.BCId}'>回复</span>");
        //    stringBuilder.AppendLine("  <div class='replyBox' style='display: none'>");
        //    //stringBuilder.AppendLine($"   <span id = 'repalyId{blogCommentDto.BCId}' class='commentId' style='display: none'>{blogCommentDto.BCId}</span>");
        //    stringBuilder.AppendLine("    <div class='comment_replyer'>");
        //    if (string.IsNullOrEmpty(userName))
        //    {
        //        stringBuilder.AppendLine($"     昵称:<input id = 'repalyTitle{blogCommentDto.BCId}' class='repalyTitle' type='text' value='匿名用户' />");
        //    }
        //    else
        //    {
        //        stringBuilder.AppendLine($"     昵称:<input id = 'repalyTitle{blogCommentDto.BCId}' class='repalyTitle' type='text' readonly='readonly' value='{userName}' />");
        //    }
        //    stringBuilder.AppendLine("    </div>");
        //    stringBuilder.AppendLine("    <div class='comment_replycontent'>");
        //    stringBuilder.AppendLine($"    <textarea id = 'repalyContent{blogCommentDto.BCId}' class='repalyContent' maxlength'800' cols='80' rows='5'></textarea>");
        //    stringBuilder.AppendLine("    </div>");
        //    stringBuilder.AppendLine("    <div class='comment_replybutton'>");
        //    stringBuilder.AppendLine($"    <input id = 'repalyButton{blogCommentDto.BCId}' class='repalyButton' refid='{blogCommentDto.BCId}' type='button' value='发表' /><input id = 'closeButton{blogCommentDto.BCId}' class='closeButton' refid='{blogCommentDto.BCId}' type='button' value='关闭' />");
        //    stringBuilder.AppendLine("    </div>");
        //    stringBuilder.AppendLine(" </div>");
        //    stringBuilder.AppendLine("</div>");

        //    return stringBuilder.ToString();
        //}

        private string CreateComment_Detail(BlogCommentDto blogCommentDto, string userName, string reference)
        {
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("<div class='comment_detail'>");
            stringBuilder.AppendLine($"  <div class='comment_title'>{blogCommentDto.PostName}<span class='comment_date'>发表于:{blogCommentDto.PostDate}</span><span class='comment_reply'>回复</span></div>");
            //stringBuilder.AppendLine(" <span class='comment_reply'>回复</span>");
            if (string.IsNullOrEmpty(reference))
            {
                stringBuilder.AppendLine($"  <div class='comment_content'>{blogCommentDto.Content}</div>");
            }
            else
            {
                stringBuilder.AppendLine($"  <div class='comment_content'>{reference}</div>");
                stringBuilder.AppendLine($"  <div class='comment_content'>{blogCommentDto.Content}</div>");
            }
            //回复界面
            stringBuilder.AppendLine(CreateCommentOperator(blogCommentDto, userName));
            stringBuilder.AppendLine("</div>");
            return(stringBuilder.ToString());
        }
Esempio n. 19
0
        /// <summary>
        /// 获取博客所有评论
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="categoryId"></param>
        /// <param name="keyWork"></param>
        /// <param name="orderFiled"></param>
        /// <param name="pageSize"></param>
        /// <param name="PageIndex"></param>
        /// <returns></returns>
        public async Task <DataResultDto <List <BlogCommentDto> > > GetList(long blogId)
        {
            DataResultDto <List <BlogCommentDto> > dataResultDto = new DataResultDto <List <BlogCommentDto> >();
            List <BlogCommentDto> list = new List <BlogCommentDto>();
            string sql = "select BCId,BlogId,ReferenceId,PostId,PostName,Content,PostDate,user.UserName,user.UserId from blogcomment left join user on user.UserId=blogcomment.PostId  where BlogId=@BlogId and blogcomment.IsDelete=0";
            IEnumerable <BlogComment> bClist = null;

            using (var connection = CreateConnection())
            {
                bClist = await connection.QueryAsync <BlogComment, User, BlogComment>(sql, (qBlogComment, quser) =>
                {
                    qBlogComment.User = quser;
                    return(qBlogComment);
                }
                                                                                      , new { BlogId = blogId }
                                                                                      , splitOn : "UserName");
            }

            BlogCommentDto BlogCommentDto = null;

            foreach (var ibc in bClist)
            {
                BlogCommentDto = Mapper.Map <BlogComment, BlogCommentDto>(ibc);
                if (ibc.PostId != 0)
                {
                    BlogCommentDto.PostId   = ibc.User.UserId;
                    BlogCommentDto.PostName = ibc.User.UserName;
                }
                else
                {
                    BlogCommentDto.PostId   = ibc.PostId;
                    BlogCommentDto.PostName = ibc.PostName;
                }

                list.Add(BlogCommentDto);
            }
            dataResultDto.Code     = 0;
            dataResultDto.DataList = list;
            return(dataResultDto);
        }
        public void update(BlogCommentDto blogcomment_dto)
        {
            try
            {
                using (TransactionScope tx = new TransactionScope(TransactionScopeOption.Required))
                {
                    BlogComment blogcomment = _blogCommentRepo.getById(blogcomment_dto.blog_comment_id);

                    if (blogcomment == null)
                    {
                        throw new ItemNotFoundException($"Blog Comment with ID {blogcomment_dto.blog_comment_id} doesnot Exit.");
                    }
                    _blogCommentMaker.copy(blogcomment, blogcomment_dto);
                    _blogCommentRepo.update(blogcomment);
                    tx.Complete();
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Esempio n. 21
0
        /// <summary>
        /// 获取用户博客的 最新的 几条博客
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="topCount"></param>
        /// <returns></returns>
        public async Task <DataResultDto <List <BlogCommentDto> > > GetBlogCommentByUserId(int topCount)
        {
            DataResultDto <List <BlogCommentDto> > dataResultDto = new DataResultDto <List <BlogCommentDto> >();
            string sql = $"select  BCId,BlogId,ReferenceId,PostId,PostName,Content,PostDate from blogcomment where IsDelete=0 order by PostDate desc  limit 0,{topCount}";
            IEnumerable <BlogComment> bClist = null;

            using (var connection = CreateConnection())
            {
                bClist = await connection.QueryAsync <BlogComment>(sql);
            }
            List <BlogCommentDto> list           = new List <BlogCommentDto>();
            BlogCommentDto        BlogCommentDto = null;

            foreach (var ibc in bClist)
            {
                BlogCommentDto = Mapper.Map <BlogComment, BlogCommentDto>(ibc);;
                list.Add(BlogCommentDto);
            }
            dataResultDto.Code     = 0;
            dataResultDto.DataList = list;

            return(dataResultDto);
        }
Esempio n. 22
0
        public async Task <IEnumerable <BlogCommentDto> > GetAllCommentsAsync(int id)
        {
            var blogComments = new List <BlogCommentDto>();

            try
            {
                using (var connection = new SqlConnection(_connectionString))
                {
                    connection.Open();

                    string     sqlProcedure = "GetAllBlogComments";
                    SqlCommand command      = new SqlCommand(sqlProcedure, connection);
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.AddWithValue("@Id", id);

                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (await reader.ReadAsync().ConfigureAwait(false))
                        {
                            var commentDto = new BlogCommentDto();

                            commentDto = MapToBlogCommentDto(reader);

                            blogComments.Add(commentDto);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }

            return(blogComments);
        }
Esempio n. 23
0
        public IActionResult CreateBlogCommentAsync(IFormCollection collection)
        {
            try
            {
                var blogCommentDto = new BlogCommentDto();

                blogCommentDto.BlogId     = Convert.ToInt32(collection["blogId"]);
                blogCommentDto.UserName   = User.Identity.Name;
                blogCommentDto.Comment    = collection["blogComment"];
                blogCommentDto.LastUpdate = DateTime.Now;
                blogCommentDto.Created    = DateTime.Now;

                bool result = _blogDal.CreateBlogComment(blogCommentDto);



                return(Redirect("/Blog/DetailsAsync/" + blogCommentDto.BlogId + "?addComment=" + result));
            }

            catch (Exception ex)
            {
                return(View("Index"));
            }
        }
Esempio n. 24
0
        public ActionResult CreateComment()
        {
            var blogComment = new BlogCommentDto();

            return(PartialView("_blogCommentPartial", blogComment));
        }