コード例 #1
0
 public BlogPostCommentModel(BlogPostComment comment)
 {
     Id       = comment.Id;
     UserName = comment.AppUser.UserName;
     Text     = comment.Text;
     Time     = comment.Time.ToString("dd/MM/yyyy");
 }
コード例 #2
0
        protected void btnSubmitComment_Click( object sender, EventArgs e )
        {
            if ( Page.IsValid )
            {
                // save comment
                Rock.Services.Cms.BlogPostCommentService commentService = new Rock.Services.Cms.BlogPostCommentService();
                BlogPostComment comment = new BlogPostComment();
                comment.Comment = txtComment.Text;
                comment.CommentDate = DateTime.Now;
                comment.EmailAddress = txtEmail.Text;
                comment.PostId = postId;
                comment.PersonName = txtName.Text;
                comment.PersonId = CurrentPersonId;

                commentService.AddBlogPostComment( comment );
                commentService.Save( comment, CurrentPersonId );

                // load comments
                post.BlogPostComments.Add( comment );
                LoadComments();

                // clear out comment fields
                txtName.Text = "";
                txtEmail.Text = "";
                txtComment.Text = "";
            }
        }
コード例 #3
0
ファイル: BlogCommentService.cs プロジェクト: youmuyou/wojilu
        public virtual void DeleteBatch(String ids)
        {
            if (strUtil.IsNullOrEmpty(ids))
            {
                return;
            }

            int[] arrId = cvt.ToIntArray(ids);
            foreach (int id in arrId)
            {
                BlogPostComment c = db.findById <BlogPostComment>(id);
                if (c == null)
                {
                    continue;
                }

                // 删除评论
                db.delete(c);

                // 重新统计父帖的数量

                Type    et     = Entity.GetType(c.GetTargetType().FullName);
                IEntity parent = ndb.findById(et, c.RootId);
                if (parent == null)
                {
                    continue;
                }

                String property = "Replies";
                int    replies  = (int)parent.get(property);
                parent.set(property, (replies - 1));
                db.update(parent, property);
            }
        }
コード例 #4
0
        public async Task <IActionResult> PostCommentNew(string postId, string comment)
        {
            if (!string.IsNullOrWhiteSpace(comment))
            {
                var bp = await _blogDbService.GetBlogPostAsync(postId);

                if (bp != null)
                {
                    var blogPostComment = new BlogPostComment
                    {
                        CommentId      = Guid.NewGuid().ToString(),
                        PostId         = postId,
                        CommentContent = comment,

                        CommentAuthorId       = User.Claims.FirstOrDefault(p => p.Type == ClaimTypes.NameIdentifier).Value,
                        CommentAuthorUsername = User.Identity.Name,
                        CommentDateCreated    = DateTime.UtcNow
                    };

                    await _blogDbService.CreateBlogPostCommentAsync(blogPostComment);
                }
            }

            return(RedirectToAction("PostView", new { postId = postId }));
        }
コード例 #5
0
        public override void Layout()
        {
            BlogApp blog = ctx.app.obj as BlogApp;

            blogService.AddHits(blog);

            set("adminUrl", to(new Admin.MyListController().Index));


            bindAppInfo(blog);

            load("blog.UserMenu", new Users.ProfileController().UserMenu);

            BlogSetting s = blog.GetSettingsObj();

            List <BlogCategory> categories = categoryService.GetByApp(ctx.app.Id);
            List <BlogPost>     newBlogs   = postService.GetNewBlog(ctx.app.Id, s.NewBlogCount);

            //List<BlogPostComment> newComments = commentService.GetNew( ctx.owner.Id, ctx.app.Id, s.NewCommentCount );
            List <BlogPostComment> newComments = BlogPostComment.find("AppId=" + ctx.app.Id).list(s.NewCommentCount);

            List <Blogroll> blogrolls = rollService.GetByApp(ctx.app.Id, ctx.owner.obj.Id);

            bindBlogroll(blogrolls);
            bindCategories(categories);
            bindPostList(newBlogs);
            bindComments(newComments);
        }
コード例 #6
0
        public ActionResult Delete(int[] ids)
        {
            if (ids == null || !ids.Any())
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var model = new BlogPostCommentsViewModel();

            model.BlogPostComments = new List <BlogPostCommentViewModel>();

            foreach (int id in ids)
            {
                BlogPostComment comment = blogPostCommentService.Find(id);
                if (comment == null)
                {
                    continue;
                }

                model.BlogPostComments.Add(new BlogPostCommentViewModel
                {
                    Id   = comment.Id,
                    Name = comment.Name,
                });
            }
            return(View(model));
        }
コード例 #7
0
 public bool InsertBlogComment(BlogPostComment comment)
 {
     try
     {
         //long BlogPostId, string User, string Email, string HomePage, string Comment));
         if (XmlManager.InsertBlogPostComment(Server.MapPath("~/App_Data/BlogComments.xml"), comment.BlogPostId,
                                              comment.User, comment.Email, comment.HomePage, comment.Comment))
         {
             string Body = comment.User + " ( " + comment.Email + " ) added a comment for a Blog Post." +
                           System.Environment.NewLine + comment.Comment;
             Utils.SendEmail("*****@*****.**", "*****@*****.**", "Comment Added for Blog Post: ", Body);
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (Exception ex)
     {
         string Body = "An error was encountered: " + Environment.NewLine + ex.ToString();
         Utils.SendEmail("*****@*****.**", "*****@*****.**", "error encountered", Body);
         return(false);
     }
 }
コード例 #8
0
ファイル: BlogService.cs プロジェクト: yumingzhe1012/wojilu
        public virtual void UpdateCommentCount(IApp blogApp)
        {
            BlogApp blog  = blogApp as BlogApp;
            int     count = BlogPostComment.find("AppId=" + blog.Id).count();

            blog.CommentCount = count;
            blog.update("CommentCount");
        }
コード例 #9
0
        //--------------------------------------------------------------------------
        public void AfterCommentInsert( BlogPostComment comment )
        {
            BlogPost post = BlogPost.findById( comment.RootId );
            User owner = User.findById( post.OwnerId );
            int appId = post.AppId;

            LayoutCacher.Update( owner, appId );
        }
コード例 #10
0
        public ActionResult DeleteConfirmed(int id)
        {
            BlogPostComment blogPostComment = db.BlogPostComments.Find(id);

            db.BlogPostComments.Remove(blogPostComment);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #11
0
        //--------------------------------------------------------------------------

        public void AfterCommentInsert(BlogPostComment comment)
        {
            BlogPost post  = BlogPost.findById(comment.RootId);
            User     owner = User.findById(post.OwnerId);
            int      appId = post.AppId;

            LayoutCacher.Update(owner, appId);
        }
コード例 #12
0
        private static void updatePost( BlogPostComment comment ) {

            BlogPost post = BlogPost.findById( comment.RootId );

            User owner = User.findById( post.OwnerId );
            int appId = post.AppId;

            BlogLayoutViewCacher.Update( owner, appId );
        }
コード例 #13
0
        private static void updatePost(BlogPostComment comment)
        {
            BlogPost post = BlogPost.findById(comment.RootId);

            User owner = User.findById(post.OwnerId);
            int  appId = post.AppId;

            BlogLayoutViewCacher.Update(owner, appId);
        }
コード例 #14
0
ファイル: BlogController.cs プロジェクト: detmach/Teknik
        public IActionResult GetCommentArticle(int commentID)
        {
            BlogPostComment comment = _dbContext.BlogPostComments.Where(p => (p.BlogPostCommentId == commentID)).First();

            if (comment != null)
            {
                return(Json(new { result = comment.Article }));
            }
            return(Json(new { error = "No article found" }));
        }
コード例 #15
0
        public async Task AddCommentAsync(long blogPostId, BlogPostComment comment)
        {
            BlogPost blogPost = await GetAsync(blogPostId);

            if (blogPost.Comments == null)
            {
                blogPost.Comments = new List <BlogPostComment>();
            }
            blogPost.Comments.Add(comment);
            await _postsDbContext.SaveChangesAsync();
        }
コード例 #16
0
 public CommentViewModel(BlogPostComment comment)
 {
     CommentId  = comment.BlogPostCommentId;
     PostId     = comment.BlogPostId;
     Post       = comment.BlogPost;
     UserId     = comment.UserId;
     User       = comment.User;
     DatePosted = comment.DatePosted;
     DateEdited = comment.DateEdited;
     Article    = comment.Article;
 }
コード例 #17
0
        //// GET: BlogPostComment
        //public ActionResult Index()
        //{
        //    return View(db.BlogPostComments.ToList());
        //}

        //// GET: BlogPostComment/Details/5
        //public ActionResult Details(int? id)
        //{
        //    if (id == null)
        //    {
        //        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        //    }
        //    BlogPostComment blogPostComment = db.BlogPostComments.Find(id);
        //    if (blogPostComment == null)
        //    {
        //        return HttpNotFound();
        //    }
        //    return View(blogPostComment);
        //}

        // GET: BlogPostComment/Create
        public ActionResult Create(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BlogPostComment blogPostComment = new BlogPostComment();

            blogPostComment.BlogId = id;
            return(View(blogPostComment));
        }
コード例 #18
0
        public ActionResult AddComment(BlogPostCommentVM model)
        {
            BlogPostComment comment = new BlogPostComment();

            comment.Content    = model.Content;
            comment.BlogPostID = model.BlogPostID;
            comment.EMail      = model.EMail;
            comment.Name       = model.Name;
            db.BlogPostComment.Add(comment);
            db.SaveChanges();
            return(RedirectToAction("Index", "SiteBlog", new { id = model.BlogPostID }));
        }
コード例 #19
0
        public async Task CreateBlogPostCommentAsync(BlogPostComment comment)
        {
            //string str = JsonConvert.SerializeObject(comment);
            //dynamic obj = JsonConvert.DeserializeObject(str);

            var obj = new dynamic[] { comment.PostId, comment };

            //var result = await _blogDbService.GetContainer("database", "container").Scripts.ExecuteStoredProcedureAsync<string>("spCreateToDoItem", new PartitionKey("Personal"), newItem);
            var result = await _postsContainer.Scripts.ExecuteStoredProcedureAsync <string>("createComment", new PartitionKey(comment.PostId), obj);

            //await this._postsContainer.CreateItemAsync<BlogPostComment>(comment, new PartitionKey(comment.PostId));
        }
コード例 #20
0
        public ActionResult AddComment(CommentVM model)
        {
            BlogPostComment comment = new BlogPostComment();

            comment.Title      = model.Title;
            comment.Content    = model.Content;
            comment.BlogPostID = model.BlogPostId;
            db.BlogPostComments.Add(comment);
            db.SaveChanges();

            return(RedirectToAction("Index", "SiteBlog", new { id = model.BlogPostId }));
        }
コード例 #21
0
 public ActionResult Edit([Bind(Include = "Id,PostId,ContentOfComment,UserId")] BlogPostComment blogPostComment)
 {
     if (ModelState.IsValid)
     {
         db.Entry(blogPostComment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.PostId = new SelectList(db.BlogPosts, "Id", "PostContent", blogPostComment.PostId);
     ViewBag.UserId = new SelectList(db.Customers, "Id", "Username", blogPostComment.UserId);
     return(View(blogPostComment));
 }
コード例 #22
0
        public ActionResult BlogCommentAdd(int blogPostId, BlogPostModel model)
        {
            if (!_blogSettings.Enabled)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var blogPost = _blogService.GetBlogPostById(blogPostId);

            if (blogPost == null || !blogPost.AllowComments)
            {
                return(RedirectToAction("Index", "Home"));
            }

            if (ModelState.IsValid)
            {
                if (_workContext.CurrentCustomer.IsGuest() && !_blogSettings.AllowNotRegisteredUsersToLeaveComments)
                {
                    ModelState.AddModelError(string.Empty, _localizationService.GetResource("Blog.Comments.OnlyRegisteredUsersLeaveComments"));
                }
                else
                {
                    var comment = new BlogPostComment()
                    {
                        BlogPostId   = blogPost.Id,
                        CustomerId   = _workContext.CurrentCustomer.Id,
                        IpAddress    = _webHelper.GetCurrentIpAddress(),
                        CommentText  = model.AddNewComment.CommentText,
                        IsApproved   = true,
                        CreatedOnUtc = DateTime.UtcNow,
                        UpdatedOnUtc = DateTime.UtcNow,
                    };
                    _customerContentService.InsertCustomerContent(comment);


                    if (_blogSettings.NotifyAboutNewBlogComments)
                    {
                        _workflowMessageService.SendBlogCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId);
                    }



                    TempData["fara.blog.addcomment.result"] = _localizationService.GetResource("Blog.Comments.SuccessfullyAdded");
                    return(RedirectToRoute("BlogPost", new { blogPostId = blogPost.Id, SeName = blogPost.GetSeName() }));
                }
            }


            PrepareBlogPostModel(model, blogPost, true);
            return(View(model));
        }
コード例 #23
0
 public async Task <bool> AddComment(BlogPostComment blogPostComment)
 {
     using (var dbConnection = Connection)
     {
         dbConnection.Open();
         return(await dbConnection.ExecuteAsync(
                    "insert into BlogPostComments values(@blogPostId,@comment)",
                    new
         {
             blogPostId = blogPostComment.BlogPostId,
             comment = blogPostComment.Comment
         }) > 0);
     }
 }
コード例 #24
0
 public static bool InsertBlogPostComment(string Path, long BlogPostId, string User, string Email,
                                          string HomePage, string Comment)
 {
     try
     {
         List <BlogPostComment> comments = new List <BlogPostComment>();
         BlogPostComment        comment  = new BlogPostComment();
         comment.Id            = Generate.NewUniqueID;
         comment.BlogPostId    = BlogPostId;
         comment.User          = User;
         comment.Email         = Email;
         comment.HomePage      = HomePage;
         comment.Comment       = Comment;
         comment.DatePublished = DateTime.Now.ToString();
         comment.Active        = false;
         System.Xml.Serialization.XmlSerializer Serializer = new System.Xml.Serialization.XmlSerializer(comments.GetType());
         if (System.IO.File.Exists(Path))
         {
             Stream       PathStream      = File.Open(Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
             StreamReader objStreamReader = new StreamReader(PathStream);
             comments = (List <BlogPostComment>)Serializer.Deserialize(objStreamReader);
             objStreamReader.Close();
             PathStream.Close();
             PathStream.Dispose();
             PathStream = File.Open(Path, FileMode.Truncate, FileAccess.Write, FileShare.Write);
             StreamWriter objStreamWriter = new StreamWriter(PathStream);
             comments.Reverse();
             comments.Add(comment);
             Serializer.Serialize(objStreamWriter, comments);
             objStreamWriter.Close();
         }
         else
         {
             comments.Add(comment);
             Stream       PathStream      = File.Open(Path, FileMode.Create, FileAccess.Write, FileShare.Write);
             StreamWriter objStreamWriter = new StreamWriter(PathStream);
             Serializer.Serialize(objStreamWriter, comments);
             objStreamWriter.Close();
             PathStream.Close();
             PathStream.Dispose();
         }
         return(true);
     }
     catch (Exception ex)
     {
         string Body = "An error was encountered: " + Environment.NewLine + ex.ToString();
         Utils.SendEmail("*****@*****.**", "*****@*****.**", "error encountered", Body);
         return(false);
     }
 }
コード例 #25
0
        public ActionResult Create([Bind(Include = "Id,PostId,ContentOfComment,UserId")] BlogPostComment blogPostComment)
        {
            if (ModelState.IsValid)
            {
                db.BlogPostComments.Add(blogPostComment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.PostId = new SelectList(db.BlogPosts, "Id", "PostContent", blogPostComment.PostId);
            ViewBag.UserId = db.BlogPostComments.Include(b => b.BlogPost).Include(b => b.Customer.Id).SingleOrDefault(b => b.Customer.Id == blogPostComment.UserId);
            //ViewBag.UserId = new SelectList(db.Customers, "Id", "Username", blogPostComment.UserId);
            return(View(blogPostComment));
        }
コード例 #26
0
        // GET: BlogPostComments/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BlogPostComment blogPostComment = db.BlogPostComments.Find(id);

            if (blogPostComment == null)
            {
                return(HttpNotFound());
            }
            return(View(blogPostComment));
        }
コード例 #27
0
ファイル: BlogService.cs プロジェクト: yasithl/CommunityApp
        public bool CreatePostComment(BlogPostComment postComment)
        {
            bool flag = false;

            try
            {
                _blogCommentRepository.Add(postComment);
                _unitOfWork.Commit();
                flag = true;
            }
            catch { }

            return(flag);
        }
コード例 #28
0
        public async Task <IActionResult> AddComment(BlogPostComment comment)
        {
            if (comment != null && ModelState.IsValid)
            {
                var result = await _blogPostsService.AddComment(comment);

                Thread.Sleep(Constants.Timers.Spinner);

                if (result)
                {
                    return(Json(JsonSerializer.Serialize(comment)));
                }
            }

            return(null);
        }
コード例 #29
0
        // GET: BlogPostComments/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            BlogPostComment blogPostComment = db.BlogPostComments.Find(id);

            if (blogPostComment == null)
            {
                return(HttpNotFound());
            }
            ViewBag.PostId = new SelectList(db.BlogPosts, "Id", "PostContent", blogPostComment.PostId);
            ViewBag.UserId = new SelectList(db.Customers, "Id", "Username", blogPostComment.UserId);
            return(View(blogPostComment));
        }
コード例 #30
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            BlogPostComment comment = blogPostCommentService.Find(id.Value);

            if (comment == null)
            {
                return(HttpNotFound());
            }
            var model = Mapper.Map <BlogPostCommentAddViewModel>(comment);

            return(View(model));
        }
コード例 #31
0
        public async Task <bool> AddBlogPostComment(BlogPostComment comment)
        {
            if (comment != null)
            {
                try
                {
                    await _blogPostCommentRepository.CreateAsync(comment);

                    return(true);
                }
                catch (Exception)
                {
                    // TODO
                }
            }

            return(false);
        }
コード例 #32
0
ファイル: BlogController.cs プロジェクト: detmach/Teknik
 public IActionResult DeleteComment(int commentID)
 {
     if (ModelState.IsValid)
     {
         BlogPostComment comment = _dbContext.BlogPostComments.Where(c => c.BlogPostCommentId == commentID).FirstOrDefault();
         if (comment != null)
         {
             if (comment.User.Username == User.Identity.Name || User.IsInRole("Admin"))
             {
                 _dbContext.BlogPostComments.Remove(comment);
                 _dbContext.SaveChanges();
                 return(Json(new { result = true }));
             }
             return(Json(new { error = "You don't have permission to delete this comment" }));
         }
         return(Json(new { error = "No comment found" }));
     }
     return(Json(new { error = "Invalid Parameters" }));
 }
コード例 #33
0
        public async Task <ActionResult> Create([Bind(Include = "BlogPostCommentId,BlogId,Comment,CommentedUser,CommentedDateTime")] BlogPostComment blogPostComment)
        {
            BlogPost blogPost = await DocumentRepository <BlogPost> .GetItemAsync(blogPostComment.BlogId);

            if (ModelState.IsValid)
            {
                blogPostComment.CommentedUser     = User.Identity.Name;
                blogPostComment.CommentedDateTime = DateTime.Now;

                if (blogPost.Comments == null)
                {
                    blogPost.Comments = new List <BlogPostComment>();
                }
                blogPost.Comments.Add(blogPostComment);

                await DocumentRepository <BlogPost> .UpdateItemAsync(blogPost.BlogId, blogPost);
            }
            return(RedirectToAction("Details", "BlogPost", new { id = blogPost.BlogId }));
        }
コード例 #34
0
 public void AfterCommentDelete( BlogPostComment comment )
 {
 }