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
Improvement - Blog picture - use localizable alternate text and title attributes for a picture
KrzysztofPajakd32c930ea764
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Blog/_CreateOrUpdate.TabInfo.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Blog/_CreateOrUpdate.TabInfo.cshtmlindex bfbca2b61..45117edfc 100644--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Blog/_CreateOrUpdate.TabInfo.cshtml+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Blog/_CreateOrUpdate.TabInfo.cshtml@@ -99,6 +99,12 @@<div class="col-md-9 col-sm-9"><admin-input asp-for="PictureId" /><span asp-validation-for="PictureId"></span>+ @if (!string.IsNullOrEmpty(Model.PictureId))+ {+ <label class="control-label">+ <a class='k-link' href='javascript:OpenWindow("@Url.Action("PicturePopup", "Blog", new { area = Constants.AreaAdmin })/?blogpostId=@(Model.Id)", 800, 600, true);'>@Loc["Admin.Common.Picture.Attributes"]</a>+ </label>+ }</div></div><div class="form-group">diff --git a/src/Web/Grand.Web.Admin/Controllers/BlogController.cs b/src/Web/Grand.Web.Admin/Controllers/BlogController.csindex 41d6e1ffb..3df7bd842 100644--- a/src/Web/Grand.Web.Admin/Controllers/BlogController.cs+++ b/src/Web/Grand.Web.Admin/Controllers/BlogController.cs@@ -9,6 +9,7 @@ using Grand.Infrastructure;using Grand.Web.Admin.Extensions;using Grand.Web.Admin.Interfaces;using Grand.Web.Admin.Models.Blogs;+using Grand.Web.Admin.Models.Common;using Grand.Web.Common.DataSource;using Grand.Web.Common.Filters;using Grand.Web.Common.Security.Authorization;@@ -34,6 +35,7 @@ namespace Grand.Web.Admin.Controllersprivate readonly IWorkContext _workContext;private readonly IGroupService _groupService;private readonly IDateTimeService _dateTimeService;+ private readonly IPictureViewModelService _pictureViewModelService;private readonly SeoSettings _seoSettings;#endregion@@ -49,6 +51,7 @@ namespace Grand.Web.Admin.ControllersIWorkContext workContext,IGroupService groupService,IDateTimeService dateTimeService,+ IPictureViewModelService pictureViewModelService,SeoSettings seoSettings){_blogService = blogService;@@ -59,6 +62,7 @@ namespace Grand.Web.Admin.Controllers_workContext = workContext;_groupService = groupService;_dateTimeService = dateTimeService;+ _pictureViewModelService = pictureViewModelService;_seoSettings = seoSettings;}@@ -231,6 +235,50 @@ namespace Grand.Web.Admin.Controllers#endregion+ #region Picture++ [PermissionAuthorizeAction(PermissionActionName.Preview)]+ public async Task<IActionResult> PicturePopup(string blogpostId)+ {+ var blogpost = await _blogService.GetBlogPostById(blogpostId);+ if (blogpost == null)+ return Content("Blog post not exist");++ if (string.IsNullOrEmpty(blogpost.PictureId))+ return Content("Picture not exist");++ return View("PicturePopup", await _pictureViewModelService.PreparePictureModel(blogpost.PictureId, blogpost.Id));+ }++ [PermissionAuthorizeAction(PermissionActionName.Edit)]+ [HttpPost]+ public async Task<IActionResult> PicturePopup(PictureModel model)+ {+ if (ModelState.IsValid)+ {+ var blogpost = await _blogService.GetBlogPostById(model.ObjectId);+ if (blogpost == null)+ throw new ArgumentException("No blog post found with the specified id");++ if (string.IsNullOrEmpty(blogpost.PictureId))+ throw new ArgumentException("No picture found with the specified id");++ if (blogpost.PictureId != model.Id)+ throw new ArgumentException("Picture ident doesn't fit with blog post");++ await _pictureViewModelService.UpdatePicture(model);++ ViewBag.RefreshPage = true;+ return View("PicturePopup", model);+ }++ Error(ModelState);++ return View("PicturePopup", model);+ }++ #endregion+#region Categoriespublic IActionResult CategoryList() => View();diff --git a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostHandler.cs b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostHandler.csindex 8275756c1..f5aca6a75 100644--- a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostHandler.cs@@ -94,14 +94,21 @@ namespace Grand.Web.Features.Handlers.Blogs{if (!string.IsNullOrEmpty(blogPost.PictureId)){+ var picture = await _pictureService.GetPictureById(blogPost.PictureId);var pictureModel = new PictureModel{Id = blogPost.PictureId,FullSizeImageUrl = await _pictureService.GetPictureUrl(blogPost.PictureId),- ImageUrl = await _pictureService.GetPictureUrl(blogPost.PictureId, _mediaSettings.BlogThumbPictureSize),- Title = string.Format(_translationService.GetResource("Media.Blog.ImageLinkTitleFormat"), blogPost.Title),- AlternateText = string.Format(_translationService.GetResource("Media.Blog.ImageAlternateTextFormat"), blogPost.Title)+ ImageUrl = await _pictureService.GetPictureUrl(blogPost.PictureId, _mediaSettings.BlogThumbPictureSize)};+ //"title" attribute+ pictureModel.Title = (picture != null && !string.IsNullOrEmpty(picture.GetTranslation(x => x.TitleAttribute, _workContext.WorkingLanguage.Id))) ?+ picture.GetTranslation(x => x.TitleAttribute, _workContext.WorkingLanguage.Id) :+ string.Format(_translationService.GetResource("Media.Blog.ImageLinkTitleFormat"), blogPost.Title);+ //"alt" attribute+ pictureModel.AlternateText = (picture != null && !string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute, _workContext.WorkingLanguage.Id))) ?+ picture.GetTranslation(x => x.AltAttribute, _workContext.WorkingLanguage.Id) :+ string.Format(_translationService.GetResource("Media.Blog.ImageAlternateTextFormat"), blogPost.Title);model.PictureModel = pictureModel;}diff --git a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostListHandler.cs b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostListHandler.csindex c276eeaca..cf94c0e2b 100644--- a/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostListHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/Blogs/GetBlogPostListHandler.cs@@ -126,14 +126,23 @@ namespace Grand.Web.Features.Handlers.Blogs{if (!string.IsNullOrEmpty(blogPost.PictureId)){+ var picture = await _pictureService.GetPictureById(blogPost.PictureId);+var pictureModel = new PictureModel {Id = blogPost.PictureId,FullSizeImageUrl = await _pictureService.GetPictureUrl(blogPost.PictureId),ImageUrl = await _pictureService.GetPictureUrl(blogPost.PictureId, _mediaSettings.BlogThumbPictureSize),- Title = string.Format(_translationService.GetResource("Media.Blog.ImageLinkTitleFormat"), blogPost.Title),- AlternateText = string.Format(_translationService.GetResource("Media.Blog.ImageAlternateTextFormat"), blogPost.Title)};+ //"title" attribute+ pictureModel.Title = (picture != null && !string.IsNullOrEmpty(picture.GetTranslation(x => x.TitleAttribute, _workContext.WorkingLanguage.Id))) ?+ picture.GetTranslation(x => x.TitleAttribute, _workContext.WorkingLanguage.Id) :+ string.Format(_translationService.GetResource("Media.Blog.ImageLinkTitleFormat"), blogPost.Title);+ //"alt" attribute+ pictureModel.AlternateText = (picture != null && !string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute, _workContext.WorkingLanguage.Id))) ?+ picture.GetTranslation(x => x.AltAttribute, _workContext.WorkingLanguage.Id) :+ string.Format(_translationService.GetResource("Media.Blog.ImageAlternateTextFormat"), blogPost.Title);+model.PictureModel = pictureModel;}}diff --git a/src/Web/Grand.Web/Features/Handlers/Blogs/GetHomePageBlogHandler.cs b/src/Web/Grand.Web/Features/Handlers/Blogs/GetHomePageBlogHandler.csindex 9403a45ea..998507fb7 100644--- a/src/Web/Grand.Web/Features/Handlers/Blogs/GetHomePageBlogHandler.cs+++ b/src/Web/Grand.Web/Features/Handlers/Blogs/GetHomePageBlogHandler.cs@@ -77,6 +77,8 @@ namespace Grand.Web.Features.Handlers.Blogs//prepare picture modelif (!string.IsNullOrEmpty(post.PictureId)){+ var picture = await _pictureService.GetPictureById(post.PictureId);+var pictureModel = new PictureModel{Id = post.PictureId,@@ -85,6 +87,15 @@ namespace Grand.Web.Features.Handlers.BlogsTitle = string.Format(_translationService.GetResource("Media.Blog.ImageLinkTitleFormat"), post.Title),AlternateText = string.Format(_translationService.GetResource("Media.Blog.ImageAlternateTextFormat"), post.Title)};+ //"title" attribute+ pictureModel.Title = (picture != null && !string.IsNullOrEmpty(picture.GetTranslation(x => x.TitleAttribute, _workContext.WorkingLanguage.Id))) ?+ picture.GetTranslation(x => x.TitleAttribute, _workContext.WorkingLanguage.Id) :+ string.Format(_translationService.GetResource("Media.Blog.ImageLinkTitleFormat"), post.Title);+ //"alt" attribute+ pictureModel.AlternateText = (picture != null && !string.IsNullOrEmpty(picture.GetTranslation(x => x.AltAttribute, _workContext.WorkingLanguage.Id))) ?+ picture.GetTranslation(x => x.AltAttribute, _workContext.WorkingLanguage.Id) :+ string.Format(_translationService.GetResource("Media.Blog.ImageAlternateTextFormat"), post.Title);+item.PictureModel = pictureModel;}model.Items.Add(item);