Open-source eCommerce platform for C# and ASP.NET Core 10 with MongoDB. Build multi-store shops and multi-vendor marketplaces with B2B/B2C, REST API, plugins, Vue 3 and Docker.
C# aspnet-corecsharpdockerdotnetecommerceecommerce-platformmongodbmulti-storemulti-vendornosqlonline-shopshoppingcart
Minor improvements in add blog comment
support8ce7126a29cb
diff --git a/src/Web/Grand.Web/Controllers/BlogController.cs b/src/Web/Grand.Web/Controllers/BlogController.csindex 6191b64f8..42a6dd395 100644--- a/src/Web/Grand.Web/Controllers/BlogController.cs+++ b/src/Web/Grand.Web/Controllers/BlogController.cs@@ -5,6 +5,7 @@ using Grand.Business.Core.Interfaces.Common.Localization;using Grand.Business.Core.Interfaces.Common.Security;using Grand.Business.Core.Utilities.Common.Security;using Grand.Domain.Blogs;+using Grand.Domain.Customers;using Grand.Infrastructure;using Grand.Web.Commands.Models.Blogs;using Grand.Web.Common.Controllers;@@ -16,6 +17,7 @@ using Grand.Web.Models.Blogs;using MediatR;using Microsoft.AspNetCore.Http;using Microsoft.AspNetCore.Mvc;+using Microsoft.Extensions.DependencyInjection;namespace Grand.Web.Controllers{@@ -153,14 +155,20 @@ namespace Grand.Web.Controllersif (ModelState.IsValid){- await _mediator.Send(new InsertBlogCommentCommand { Model = model, BlogPost = blogPost });+ var blogComment = await _mediator.Send(new InsertBlogCommentCommand { Model = model, BlogPost = blogPost });//notificationawait _mediator.Publish(new BlogCommentEvent(blogPost, model));return Json(new{- success = true+ success = true,+ message = _translationService.GetResource("Blog.Comments.SuccessfullyAdded"),+ model = new {+ blogComment.CommentText,+ CreatedOn = HttpContext.RequestServices.GetService<IDateTimeService>().ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc),+ CustomerName = _workContext.CurrentCustomer.FormatUserName(HttpContext.RequestServices.GetService<CustomerSettings>().CustomerNameFormat)+ }});}return Json(newdiff --git a/src/Web/Grand.Web/Views/Blog/BlogPost.cshtml b/src/Web/Grand.Web/Views/Blog/BlogPost.cshtmlindex 7f2854d08..0eb95a414 100644--- a/src/Web/Grand.Web/Views/Blog/BlogPost.cshtml+++ b/src/Web/Grand.Web/Views/Blog/BlogPost.cshtml@@ -8,6 +8,7 @@pagebuilder.AddMetaDescriptionParts(Model.MetaDescription);pagebuilder.AddMetaKeywordParts(Model.MetaKeywords);}+@section left {@await Component.InvokeAsync("Widget", new { widgetZone = "left_side_column_blog_before" })@await Component.InvokeAsync("BlogCategories")@@ -17,6 +18,7 @@@await Component.InvokeAsync("BlogTags")@await Component.InvokeAsync("Widget", new { widgetZone = "left_side_column_blog_after" })}+<div class="page blogpost-page">@await Component.InvokeAsync("Widget", new { widgetZone = "blogpost_page_top", additionalData = Model.Id })<div class="card mt-3">@@ -49,7 +51,7 @@@for (var i = 0; i < Model.Tags.Count; i++){var tag = Model.Tags[i];- <a class="btn btn-sm btn-light mr-2 mb-2" href="@Url.RouteUrl("BlogByTag", new { tag})">@tag</a>+ <a class="btn btn-sm btn-light mr-2 mb-2" href="@Url.RouteUrl("BlogByTag", new { tag })">@tag</a>}</div>}@@ -71,7 +73,7 @@</div><validation-observer v-slot="{ handleSubmit }"><form id="addBlogComment" asp-controller="Blog" asp-action="BlogPost" asp-route-id="@Model.Id" method="post" v-on:submit.prevent="handleSubmit(blog.submitBlogComment)">- <input type="hidden" name="Id" value="@Model.Id" />+ <input type="hidden" name="Id" value="@Model.Id"/><div class="form-fields"><div class="form-group"><validation-provider tag="div" rules="required" v-slot="{ errors, classes }">@@ -86,24 +88,26 @@@if (Model.AddNewComment.DisplayCaptcha){<div class="captcha-box">- <captcha />+ <captcha/></div>}</div><div class="buttons text-xs-center text-md-left generalMarginSupporter">- <input type="submit" asp-action="BlogCommentAdd" name="add-comment" class="btn btn-info blog-post-add-comment-button" value="@Loc["Blog.Comments.SubmitButton"]" />+ <input type="submit" asp-action="BlogCommentAdd" name="add-comment" class="btn btn-info blog-post-add-comment-button" value="@Loc["Blog.Comments.SubmitButton"]"/></div></form></validation-observer><script asp-location="Footer" asp-order="300">var blog = new Vue({- data: () => ({- @{- <text>- CommentText: '',- </text>+ data: function () {+ return {+ Model: null,+ CommentText: ''}- }),+ },+ created() {+ this.Model = @Json.Serialize(Model.Comments);+ },methods: {submitBlogComment() {var form = document.getElementById("addBlogComment");@@ -118,41 +122,50 @@}}).then(function (response) {if (response.data.success == true){- location.reload();- }- vm.displayBarNotification(response.data.message, '', 'error', 3500);+ blog.CommentText = ' ';+ vm.displayBarNotification(response.data.message, '', 'success', 3000);+ if (response.data.model){+ blog.addComment(response.data.model)+ }+ } else {+ vm.displayBarNotification(response.data.message, '', 'error', 3500);+ }})+ },+ addComment(model) {+ // Add object item to array+ this.Model.push(model);}}});</script></div>- if (Model.Comments.Any())- {+ <template v-if="blog.Model.length > 0"><div class="comment-list">- <h4 class="generalTitle generalMarginSupporter"><strong>@Loc["Blog.Comments"]</strong></h4>+ <h4 class="generalTitle generalMarginSupporter">+ <strong>@Loc["Blog.Comments"]</strong>+ </h4><div class="comments">- @foreach (var comment in Model.Comments)- {+ <template v-for="comment in blog.Model"><div class="card mb-3"><div class="card-header"><div class="d-inline-flex w-100">- <h6 class="mb-0">@comment.CustomerName</h6>+ <h6 class="mb-0">{{comment.CustomerName}}</h6><b-icon icon="calendar2-check" variant="info" class="mx-2"></b-icon><small class="date text-muted"><span>@Loc["Blog.Comments.CreatedOn"]:</span>- <span>@comment.CreatedOn.ToString("g")</span>+ <span>{{new Date( comment.CreatedOn).toDateString()}}</span></small></div></div><div class="card-body">- @comment.CommentText+ {{comment.CommentText}}</div></div>- }+ </template></div></div>- }- }+ </template>+ }@await Component.InvokeAsync("Widget", new { widgetZone = "blogpost_page_bottom", additionalData = Model.Id })</div>\ No newline at end of file