Skip to content

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.

Refactor path handling in LanguageViewModelService

KrzysztofPajakfb975466b21a
diff --git a/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs b/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs
index d9b5cfd73..d9e253c94 100644
--- a/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs
+++ b/src/Core/Grand.SharedKernel/Extensions/CommonPath.cs
@@ -39,16 +39,4 @@ public static class CommonPath
path = path.Replace("~/", "").TrimStart('/');
return Path.Combine(BaseDirectory, path);
}
-
-
- /// <summary>
- /// Maps a virtual path to a physical disk path. (not for tenants)
- /// </summary>
- /// <param name="path">The path to map. E.g. "~/bin"</param>
- /// <returns>The physical path. E.g. "c:\inetpub\wwwroot\"</returns>
- public static string WebHostMapPath(string path)
- {
- path = path.Replace("~/", "").TrimStart('/');
- return Path.Combine(WebHostEnvironment, path);
- }
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Services/LanguageViewModelService.cs b/src/Web/Grand.Web.Admin/Services/LanguageViewModelService.cs
index 85357a4f7..35aad83fd 100644
--- a/src/Web/Grand.Web.Admin/Services/LanguageViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/LanguageViewModelService.cs
@@ -1,25 +1,37 @@
using Grand.Business.Core.Interfaces.Common.Directory;
using Grand.Business.Core.Interfaces.Common.Localization;
using Grand.Domain.Localization;
-using Grand.SharedKernel.Extensions;
using Grand.Web.Admin.Extensions.Mapping;
using Grand.Web.Admin.Interfaces;
using Grand.Web.Admin.Models.Localization;
+using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace Grand.Web.Admin.Services;
public class LanguageViewModelService : ILanguageViewModelService
{
+
+ #region Fields
+
+ private readonly ILanguageService _languageService;
+ private readonly ITranslationService _translationService;
+ private readonly ICurrencyService _currencyService;
+ private readonly IWebHostEnvironment _hostingEnvironment;
+
+ #endregion
+
#region Constructors
public LanguageViewModelService(ILanguageService languageService,
ITranslationService translationService,
- ICurrencyService currencyService)
+ ICurrencyService currencyService,
+ IWebHostEnvironment hostingEnvironment)
{
_translationService = translationService;
_languageService = languageService;
_currencyService = currencyService;
+ _hostingEnvironment = hostingEnvironment;
}
#endregion
@@ -27,9 +39,9 @@ public class LanguageViewModelService : ILanguageViewModelService
public virtual void PrepareFlagsModel(LanguageModel model)
{
ArgumentNullException.ThrowIfNull(model);
-
+ var filepath = Path.Combine(_hostingEnvironment.WebRootPath, "assets/images/flags");
model.FlagFileNames = Directory
- .EnumerateFiles(CommonPath.WebHostMapPath("/assets/images/flags/"), "*.png", SearchOption.TopDirectoryOnly)
+ .EnumerateFiles(filepath, "*.png", SearchOption.TopDirectoryOnly)
.Select(Path.GetFileName)
.ToList();
}
@@ -149,12 +161,4 @@ public class LanguageViewModelService : ILanguageViewModelService
resources = resources.AsQueryable();
return (resources.Skip((pageIndex - 1) * pageSize).Take(pageSize), resources.Count());
}
-
- #region Fields
-
- private readonly ILanguageService _languageService;
- private readonly ITranslationService _translationService;
- private readonly ICurrencyService _currencyService;
-
- #endregion
}
\ No newline at end of file