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.

Minor refactoring

KrzysztofPajak92ebe96e8546
diff --git a/src/Business/Grand.Business.Customers/Extensions/AffiliateExtensions.cs b/src/Business/Grand.Business.Customers/Extensions/AffiliateExtensions.cs
index 5375edc63..82f448940 100644
--- a/src/Business/Grand.Business.Customers/Extensions/AffiliateExtensions.cs
+++ b/src/Business/Grand.Business.Customers/Extensions/AffiliateExtensions.cs
@@ -1,12 +1,11 @@
using Grand.Business.Common.Extensions;
using Grand.Business.Customers.Interfaces;
-using Grand.Infrastructure;
using Grand.Domain.Affiliates;
using Grand.Domain.Seo;
+using Grand.Infrastructure.Extensions;
using Grand.SharedKernel.Extensions;
using System;
using System.Threading.Tasks;
-using Grand.Infrastructure.Extensions;
namespace Grand.Business.Customers.Extensions
{
@@ -44,19 +43,19 @@ namespace Grand.Business.Customers.Extensions
/// Generate affilaite URL
/// </summary>
/// <param name="affiliate">Affiliate</param>
- /// <param name="workContext">WorkContext</param>
+ /// <param name="host">Host</param>
/// <returns>Generated affilaite URL</returns>
- public static string GenerateUrl(this Affiliate affiliate, IWorkContext workContext)
+ public static string GenerateUrl(this Affiliate affiliate, string host)
{
if (affiliate == null)
throw new ArgumentNullException(nameof(affiliate));
- if (workContext == null)
- throw new ArgumentNullException(nameof(workContext));
+ if (string.IsNullOrEmpty(host))
+ throw new ArgumentNullException(nameof(host));
- var storeUrl = workContext.CurrentHost == null ? workContext.CurrentStore.Url : workContext.CurrentHost.Url.TrimEnd('/');
- var url = !string.IsNullOrEmpty(affiliate.FriendlyUrlName) ?
- CommonExtensions.ModifyQueryString(storeUrl, "affiliate", affiliate.FriendlyUrlName) : CommonExtensions.ModifyQueryString(storeUrl, "affiliateid", affiliate.Id);
+ var url = !string.IsNullOrEmpty(affiliate.FriendlyUrlName) ?
+ CommonExtensions.ModifyQueryString(host, "affiliate", affiliate.FriendlyUrlName)
+ : CommonExtensions.ModifyQueryString(host, "affiliateid", affiliate.Id);
return url;
}
diff --git a/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs b/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs
index c153bae4b..b31064949 100644
--- a/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs
+++ b/src/Tests/Grand.Business.Customers.Tests/Extensions/AffiliateExtensionsTests.cs
@@ -85,7 +85,7 @@ namespace Grand.Business.Customers.Tests.Extensions
Id = id
};
_workContextMock.Setup(c => c.CurrentStore).Returns(new Domain.Stores.Store() { Url = _fakeStoreUrl });
- Assert.AreEqual(string.Format(_expectedFormat, "affiliateid", id), affiliate.GenerateUrl(_workContextMock.Object));
+ Assert.AreEqual(string.Format(_expectedFormat, "affiliateid", id), affiliate.GenerateUrl("http://localhost/"));
//_webHelperMock.Verify(c => c.ModifyQueryString(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once);
}
@@ -97,7 +97,7 @@ namespace Grand.Business.Customers.Tests.Extensions
FriendlyUrlName = friendlyUrl
};
_workContextMock.Setup(c => c.CurrentStore).Returns(new Domain.Stores.Store() { Url = _fakeStoreUrl });
- Assert.AreEqual(string.Format(_expectedFormat, "affiliate", friendlyUrl), affiliate.GenerateUrl(_workContextMock.Object));
+ Assert.AreEqual(string.Format(_expectedFormat, "affiliate", friendlyUrl), affiliate.GenerateUrl("http://localhost/"));
}
[TestMethod()]
diff --git a/src/Web/Grand.Web.Admin/Services/AffiliateViewModelService.cs b/src/Web/Grand.Web.Admin/Services/AffiliateViewModelService.cs
index e1ccebf53..aa51e90b2 100644
--- a/src/Web/Grand.Web.Admin/Services/AffiliateViewModelService.cs
+++ b/src/Web/Grand.Web.Admin/Services/AffiliateViewModelService.cs
@@ -63,7 +63,9 @@ namespace Grand.Web.Admin.Services
{
model.Id = affiliate.Id;
model.Name = affiliate.Name;
- model.Url = affiliate.GenerateUrl(_workContext);
+
+ var host = _workContext.CurrentHost == null ? _workContext.CurrentStore.Url.TrimEnd('/') : _workContext.CurrentHost.Url.TrimEnd('/');
+ model.Url = affiliate.GenerateUrl(host);
if (!excludeProperties)
{
model.AdminComment = affiliate.AdminComment;