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.

Email Accounts per Store (#680)

Copilot3f116e870890
diff --git a/src/Business/Grand.Business.Core/Interfaces/Messages/IEmailAccountService.cs b/src/Business/Grand.Business.Core/Interfaces/Messages/IEmailAccountService.cs
index 10b3f2f8c..00fbf3cda 100644
--- a/src/Business/Grand.Business.Core/Interfaces/Messages/IEmailAccountService.cs
+++ b/src/Business/Grand.Business.Core/Interfaces/Messages/IEmailAccountService.cs
@@ -1,4 +1,5 @@
-using Grand.Domain.Messages;
+using Grand.Domain;
+using Grand.Domain.Messages;
namespace Grand.Business.Core.Interfaces.Messages;
@@ -30,8 +31,11 @@ public interface IEmailAccountService
Task<EmailAccount> GetEmailAccountById(string emailAccountId);
/// <summary>
- /// Gets all email accounts
+ /// Gets all email accounts, optionally filtered by store, with pagination support.
/// </summary>
- /// <returns>Email accounts list</returns>
- Task<IList<EmailAccount>> GetAllEmailAccounts();
+ /// <param name="storeId">Store identifier; pass empty string to return all accounts</param>
+ /// <param name="pageIndex">Page index (0-based)</param>
+ /// <param name="pageSize">Page size</param>
+ /// <returns>Paged list of email accounts</returns>
+ Task<IPagedList<EmailAccount>> GetAllEmailAccounts(string storeId = "", int pageIndex = 0, int pageSize = int.MaxValue);
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Messages/Services/EmailAccountService.cs b/src/Business/Grand.Business.Messages/Services/EmailAccountService.cs
index af52922b0..5275730b6 100644
--- a/src/Business/Grand.Business.Messages/Services/EmailAccountService.cs
+++ b/src/Business/Grand.Business.Messages/Services/EmailAccountService.cs
@@ -1,5 +1,6 @@
using Grand.Business.Core.Interfaces.Messages;
using Grand.Data;
+using Grand.Domain;
using Grand.Domain.Messages;
using Grand.Infrastructure.Caching;
using Grand.Infrastructure.Caching.Constants;
@@ -109,8 +110,7 @@ public class EmailAccountService : IEmailAccountService
public virtual async Task DeleteEmailAccount(EmailAccount emailAccount)
{
ArgumentNullException.ThrowIfNull(emailAccount);
- var emailAccounts = await GetAllEmailAccounts();
- if (emailAccounts.Count == 1)
+ if (_emailAccountRepository.Table.Take(2).Count() <= 1)
throw new GrandException("You cannot delete this email account. At least one account is required.");
await _emailAccountRepository.DeleteAsync(emailAccount);
@@ -134,16 +134,20 @@ public class EmailAccountService : IEmailAccountService
}
/// <summary>
- /// Gets all email accounts
+ /// Gets all email accounts, optionally filtered by store, with pagination support.
/// </summary>
- /// <returns>Email accounts list</returns>
- public virtual async Task<IList<EmailAccount>> GetAllEmailAccounts()
+ /// <param name="storeId">Store identifier; pass empty string to return all accounts</param>
+ /// <param name="pageIndex">Page index (0-based)</param>
+ /// <param name="pageSize">Page size</param>
+ /// <returns>Paged list of email accounts</returns>
+ public virtual async Task<IPagedList<EmailAccount>> GetAllEmailAccounts(string storeId = "", int pageIndex = 0, int pageSize = int.MaxValue)
{
- return await _cacheBase.GetAsync(CacheKey.EMAILACCOUNT_ALL_KEY, async () =>
- {
- var query = from ea in _emailAccountRepository.Table
- select ea;
- return await Task.FromResult(query.ToList());
- });
+ var query = from ea in _emailAccountRepository.Table
+ select ea;
+
+ if (!string.IsNullOrEmpty(storeId))
+ query = query.Where(ea => ea.StoreId == storeId);
+
+ return await PagedList<EmailAccount>.Create(query, pageIndex, pageSize);
}
}
\ No newline at end of file
diff --git a/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs b/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs
index b72605454..21fa6f7de 100644
--- a/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs
+++ b/src/Business/Grand.Business.Messages/Services/MessageProviderService.cs
@@ -96,10 +96,9 @@ public class MessageProviderService : IMessageProviderService
string languageId)
{
var emailAccounId = messageTemplate.GetTranslation(mt => mt.EmailAccountId, languageId);
- var emailAccount = (await _emailAccountService.GetEmailAccountById(emailAccounId) ??
- await _emailAccountService.GetEmailAccountById(_emailAccountSettings
- .DefaultEmailAccountId)) ??
- (await _emailAccountService.GetAllEmailAccounts()).FirstOrDefault();
+ var emailAccount = await _emailAccountService.GetEmailAccountById(emailAccounId);
+ emailAccount ??= await _emailAccountService.GetEmailAccountById(_emailAccountSettings.DefaultEmailAccountId);
+ emailAccount ??= (await _emailAccountService.GetAllEmailAccounts()).FirstOrDefault();
return emailAccount;
}
diff --git a/src/Core/Grand.Domain/Messages/EmailAccount.cs b/src/Core/Grand.Domain/Messages/EmailAccount.cs
index dfbe59f38..4eee08453 100644
--- a/src/Core/Grand.Domain/Messages/EmailAccount.cs
+++ b/src/Core/Grand.Domain/Messages/EmailAccount.cs
@@ -45,4 +45,10 @@ public class EmailAccount : BaseEntity
/// Provides a way of specifying the SSL and/or TLS encryption that should be used for a connection
/// </summary>
public int SecureSocketOptionsId { get; set; }
+
+ /// <summary>
+ /// Gets or sets the store identifier this email account belongs to.
+ /// An empty string means this is a global/shared email account.
+ /// </summary>
+ public string StoreId { get; set; }
}
\ No newline at end of file
diff --git a/src/Core/Grand.Infrastructure/Caching/Constants/MessagesCacheKey.cs b/src/Core/Grand.Infrastructure/Caching/Constants/MessagesCacheKey.cs
index 6cb16902c..6339f6c40 100644
--- a/src/Core/Grand.Infrastructure/Caching/Constants/MessagesCacheKey.cs
+++ b/src/Core/Grand.Infrastructure/Caching/Constants/MessagesCacheKey.cs
@@ -43,13 +43,6 @@ public static partial class CacheKey
/// </remarks>
public static string EMAILACCOUNT_BY_ID_KEY => "Grand.emailaccount.id-{0}";
- /// <summary>
- /// Key for caching
- /// </summary>
- /// <remarks>
- /// </remarks>
- public static string EMAILACCOUNT_ALL_KEY => "Grand.emailaccount.all";
-
/// <summary>
/// Key pattern to clear cache
/// </summary>
diff --git a/src/Tests/Grand.Business.Messages.Tests/Services/EmailAccountServiceTests.cs b/src/Tests/Grand.Business.Messages.Tests/Services/EmailAccountServiceTests.cs
index 655b0bb17..83650685c 100644
--- a/src/Tests/Grand.Business.Messages.Tests/Services/EmailAccountServiceTests.cs
+++ b/src/Tests/Grand.Business.Messages.Tests/Services/EmailAccountServiceTests.cs
@@ -48,8 +48,7 @@ public class EmailAccountServiceTests
[TestMethod]
public async Task DeleteEmailAccount_InvokeExpectedMethods()
{
- _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<EmailAccount>>>>()))
- .Returns(Task.FromResult(new List<EmailAccount> { new(), new() }));
+ _repository.Setup(r => r.Table).Returns(new List<EmailAccount> { new(), new() }.AsQueryable());
await _service.DeleteEmailAccount(new EmailAccount());
_repository.Verify(c => c.DeleteAsync(It.IsAny<EmailAccount>()), Times.Once);
_mediatorMock.Verify(c => c.Publish(It.IsAny<EntityDeleted<EmailAccount>>(), default), Times.Once);
@@ -57,11 +56,10 @@ public class EmailAccountServiceTests
}
[TestMethod]
- public void DeleteEmailAccount_ExistOnlyOneAccount_ThrowException()
+ public async Task DeleteEmailAccount_ExistOnlyOneAccount_ThrowException()
{
//we can't delete account if exist only one
- _cacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), It.IsAny<Func<Task<List<EmailAccount>>>>()))
- .Returns(Task.FromResult(new List<EmailAccount> { new() }));
- Assert.ThrowsExactlyAsync<GrandException>(async () => await _service.DeleteEmailAccount(new EmailAccount()));
+ _repository.Setup(r => r.Table).Returns(new List<EmailAccount> { new() }.AsQueryable());
+ await Assert.ThrowsExactlyAsync<GrandException>(async () => await _service.DeleteEmailAccount(new EmailAccount()));
}
}
\ No newline at end of file
diff --git a/src/Tests/Grand.Business.Messages.Tests/Services/MessageProviderServiceTest.cs b/src/Tests/Grand.Business.Messages.Tests/Services/MessageProviderServiceTest.cs
index aba38a5bb..7566cd2b8 100644
--- a/src/Tests/Grand.Business.Messages.Tests/Services/MessageProviderServiceTest.cs
+++ b/src/Tests/Grand.Business.Messages.Tests/Services/MessageProviderServiceTest.cs
@@ -4,6 +4,7 @@ using Grand.Business.Core.Interfaces.Common.Stores;
using Grand.Business.Core.Interfaces.Messages;
using Grand.Business.Core.Queries.Messages;
using Grand.Business.Messages.Services;
+using Grand.Domain;
using Grand.Domain.Catalog;
using Grand.Domain.Common;
using Grand.Domain.Customers;
@@ -51,9 +52,9 @@ public class MessageProviderServiceTest
new List<Language> { new() { Name = "English" }, new() { Name = "Polish" } } as IList<Language>));
_emailAccountServiceMock = new Mock<IEmailAccountService>();
- _emailAccountServiceMock.Setup(x => x.GetAllEmailAccounts())
- .Returns(Task.FromResult(
- new List<EmailAccount> { new() { Email = "[email protected]" } } as IList<EmailAccount>));
+ _emailAccountServiceMock.Setup(x => x.GetAllEmailAccounts(It.IsAny<string>(), It.IsAny<int>(), It.IsAny<int>()))
+ .Returns(Task.FromResult<IPagedList<EmailAccount>>(
+ new PagedList<EmailAccount>(new List<EmailAccount> { new() { Email = "[email protected]" } }, 0, int.MaxValue)));
_messageTokenProviderMock = new Mock<IMessageTokenProvider>();
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/EmailAccount/Partials/CreateOrUpdate.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/EmailAccount/Partials/CreateOrUpdate.cshtml
index aa1a85a72..66ca5ee47 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/EmailAccount/Partials/CreateOrUpdate.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/EmailAccount/Partials/CreateOrUpdate.cshtml
@@ -68,6 +68,12 @@
<admin-select asp-for="SecureSocketOptionsId" asp-items="EnumTranslationService.ToSelectList((SecureSocketOptions)Model.SecureSocketOptionsId)"/>
</div>
</div>
+ <div class="form-group">
+ <admin-label asp-for="StoreId"/>
+ <div class="col-md-9 col-sm-9">
+ <select asp-for="StoreId" asp-items="Model.AvailableStores" class="form-control"></select>
+ </div>
+ </div>
@if (!string.IsNullOrEmpty(Model.Id))
{
<div class="form-group">
diff --git a/src/Web/Grand.Web.Admin/Controllers/EmailAccountController.cs b/src/Web/Grand.Web.Admin/Controllers/EmailAccountController.cs
index e93b33183..4e94763b5 100644
--- a/src/Web/Grand.Web.Admin/Controllers/EmailAccountController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/EmailAccountController.cs
@@ -47,15 +47,14 @@ public class EmailAccountController : BaseAdminController
[PermissionAuthorizeAction(PermissionActionName.List)]
public async Task<IActionResult> List(DataSourceRequest command)
{
- var emailAccountModels = (await _emailAccountService.GetAllEmailAccounts())
- .Select(x => x.ToModel())
- .ToList();
+ var emailAccounts = await _emailAccountService.GetAllEmailAccounts(pageIndex: command.Page - 1, pageSize: command.PageSize);
+ var emailAccountModels = emailAccounts.Select(x => x.ToModel()).ToList();
foreach (var eam in emailAccountModels)
eam.IsDefaultEmailAccount = eam.Id == _emailAccountSettings.DefaultEmailAccountId;
var gridModel = new DataSourceResult {
Data = emailAccountModels,
- Total = emailAccountModels.Count
+ Total = emailAccounts.TotalCount
};
return Json(gridModel);
@@ -78,9 +77,9 @@ public class EmailAccountController : BaseAdminController
}
[PermissionAuthorizeAction(PermissionActionName.Create)]
- public IActionResult Create()
+ public async Task<IActionResult> Create()
{
- var model = _emailAccountViewModelService.PrepareEmailAccountModel();
+ var model = await _emailAccountViewModelService.PrepareEmailAccountModel();
return View(model);
}
@@ -108,7 +107,9 @@ public class EmailAccountController : BaseAdminController
//No email account found with the specified id
return RedirectToAction("List");
- return View(emailAccount.ToModel());
+ var model = emailAccount.ToModel();
+ await _emailAccountViewModelService.PrepareAvailableStores(model);
+ return View(model);
}
[HttpPost]
diff --git a/src/Web/Grand.Web.AdminShared/Interfaces/IEmailAccountViewModelService.cs b/src/Web/Grand.Web.AdminShared/Interfaces/IEmailAccountViewModelService.cs
index fb5df4b5f..e74daae03 100644
--- a/src/Web/Grand.Web.AdminShared/Interfaces/IEmailAccountViewModelService.cs
+++ b/src/Web/Grand.Web.AdminShared/Interfaces/IEmailAccountViewModelService.cs
@@ -5,7 +5,8 @@ namespace Grand.Web.AdminShared.Interfaces;
public interface IEmailAccountViewModelService
{
- EmailAccountModel PrepareEmailAccountModel();
+ Task<EmailAccountModel> PrepareEmailAccountModel();
+ Task PrepareAvailableStores(EmailAccountModel model);
Task<EmailAccount> InsertEmailAccountModel(EmailAccountModel model);
Task<EmailAccount> UpdateEmailAccountModel(EmailAccount emailAccount, EmailAccountModel model);
Task SendTestEmail(EmailAccount emailAccount, EmailAccountModel model);
diff --git a/src/Web/Grand.Web.AdminShared/Mapper/EmailAccountProfile.cs b/src/Web/Grand.Web.AdminShared/Mapper/EmailAccountProfile.cs
index f0e257525..63548d254 100644
--- a/src/Web/Grand.Web.AdminShared/Mapper/EmailAccountProfile.cs
+++ b/src/Web/Grand.Web.AdminShared/Mapper/EmailAccountProfile.cs
@@ -12,7 +12,8 @@ public class EmailAccountProfile : Profile, IAutoMapperProfile
CreateMap<EmailAccount, EmailAccountModel>()
.ForMember(dest => dest.Password, mo => mo.Ignore())
.ForMember(dest => dest.IsDefaultEmailAccount, mo => mo.Ignore())
- .ForMember(dest => dest.SendTestEmailTo, mo => mo.Ignore());
+ .ForMember(dest => dest.SendTestEmailTo, mo => mo.Ignore())
+ .ForMember(dest => dest.AvailableStores, mo => mo.Ignore());
CreateMap<EmailAccountModel, EmailAccount>()
.ForMember(dest => dest.Id, mo => mo.Ignore())
diff --git a/src/Web/Grand.Web.AdminShared/Models/Messages/EmailAccountModel.cs b/src/Web/Grand.Web.AdminShared/Models/Messages/EmailAccountModel.cs
index c0730a9a5..469cbf4b1 100644
--- a/src/Web/Grand.Web.AdminShared/Models/Messages/EmailAccountModel.cs
+++ b/src/Web/Grand.Web.AdminShared/Models/Messages/EmailAccountModel.cs
@@ -1,5 +1,6 @@
using Grand.Infrastructure.ModelBinding;
using Grand.Infrastructure.Models;
+using Microsoft.AspNetCore.Mvc.Rendering;
namespace Grand.Web.AdminShared.Models.Messages;
@@ -34,4 +35,9 @@ public class EmailAccountModel : BaseEntityModel
[GrandResourceDisplayName("Admin.Configuration.EmailAccounts.Fields.SendTestEmailTo")]
public string SendTestEmailTo { get; set; }
+
+ [GrandResourceDisplayName("Admin.Configuration.EmailAccounts.Fields.Store")]
+ public string StoreId { get; set; }
+
+ public IList<SelectListItem> AvailableStores { get; set; } = new List<SelectListItem>();
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.AdminShared/Services/EmailAccountViewModelService.cs b/src/Web/Grand.Web.AdminShared/Services/EmailAccountViewModelService.cs
index e228ad2c5..837f7522b 100644
--- a/src/Web/Grand.Web.AdminShared/Services/EmailAccountViewModelService.cs
+++ b/src/Web/Grand.Web.AdminShared/Services/EmailAccountViewModelService.cs
@@ -1,8 +1,11 @@
-using Grand.Business.Core.Interfaces.Messages;
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Common.Stores;
+using Grand.Business.Core.Interfaces.Messages;
using Grand.Domain.Messages;
using Grand.Web.AdminShared.Extensions.Mapping;
using Grand.Web.AdminShared.Interfaces;
using Grand.Web.AdminShared.Models.Messages;
+using Microsoft.AspNetCore.Mvc.Rendering;
namespace Grand.Web.AdminShared.Services;
@@ -10,22 +13,33 @@ public class EmailAccountViewModelService : IEmailAccountViewModelService
{
private readonly IEmailAccountService _emailAccountService;
private readonly IEmailSender _emailSender;
+ private readonly IStoreService _storeService;
+ private readonly ITranslationService _translationService;
- public EmailAccountViewModelService(IEmailAccountService emailAccountService, IEmailSender emailSender)
+ public EmailAccountViewModelService(IEmailAccountService emailAccountService, IEmailSender emailSender,
+ IStoreService storeService, ITranslationService translationService)
{
_emailAccountService = emailAccountService;
_emailSender = emailSender;
+ _storeService = storeService;
+ _translationService = translationService;
}
- public virtual EmailAccountModel PrepareEmailAccountModel()
+ public virtual async Task<EmailAccountModel> PrepareEmailAccountModel()
{
var model = new EmailAccountModel {
//default values
Port = 25
};
+ await PopulateAvailableStores(model);
return model;
}
+ public virtual async Task PrepareAvailableStores(EmailAccountModel model)
+ {
+ await PopulateAvailableStores(model);
+ }
+
public virtual async Task<EmailAccount> InsertEmailAccountModel(EmailAccountModel model)
{
var emailAccount = model.ToEntity();
@@ -52,4 +66,17 @@ public class EmailAccountViewModelService : IEmailAccountViewModelService
await _emailSender.SendEmail(emailAccount, subject, body, emailAccount.Email, emailAccount.DisplayName,
model.SendTestEmailTo, null);
}
+
+ private async Task PopulateAvailableStores(EmailAccountModel model)
+ {
+ model.AvailableStores.Add(new SelectListItem {
+ Value = "",
+ Text = _translationService.GetResource("Admin.Settings.StoreScope.AllStores")
+ });
+ foreach (var store in await _storeService.GetAllStores())
+ model.AvailableStores.Add(new SelectListItem {
+ Value = store.Id,
+ Text = store.Name
+ });
+ }
}
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/Create.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/Create.cshtml
new file mode 100644
index 000000000..637d25174
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/Create.cshtml
@@ -0,0 +1,34 @@
+@model EmailAccountModel
+@{
+ //page title
+ ViewBag.Title = Loc["Admin.Configuration.EmailAccounts.AddNew"];
+}
+<form asp-area="@Constants.AreaStore" asp-controller="EmailAccount" asp-action="Create" method="post">
+
+ <div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-envelope"></i>
+ @Loc["Admin.Configuration.EmailAccounts.AddNew"]
+ <small>
+ <i class="fa fa-arrow-circle-left"></i> @Html.ActionLink(Loc["Admin.Configuration.EmailAccounts.BackToList"], "List")
+ </small>
+ </div>
+ <div class="actions">
+ <button class="btn btn-success" type="submit" name="save">
+ <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]
+ </button>
+ <button class="btn btn-success" type="submit" name="save-continue">
+ <i class="fa fa-check-circle"></i> @Loc["Admin.Common.SaveContinue"]
+ </button>
+ </div>
+ </div>
+ <div class="x_content form">
+ <partial name="Partials/CreateOrUpdate" model="Model"/>
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/Edit.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/Edit.cshtml
new file mode 100644
index 000000000..f5bb6c9cf
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/Edit.cshtml
@@ -0,0 +1,40 @@
+@model EmailAccountModel
+@{
+ //page title
+ ViewBag.Title = Loc["Admin.Configuration.EmailAccounts.EditEmailAccountDetails"];
+}
+<form asp-area="@Constants.AreaStore" asp-controller="EmailAccount" asp-action="Edit" method="post">
+
+ <div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-envelope"></i>
+ @Loc["Admin.Configuration.EmailAccounts.EditEmailAccountDetails"]
+ <small>
+ <i class="fa fa-arrow-circle-left"></i> @Html.ActionLink(Loc["Admin.Configuration.EmailAccounts.BackToList"], "List")
+ </small>
+ </div>
+ <div class="actions">
+ <div class="btn-group btn-group-devided util-btn-margin-bottom-5">
+ <button class="btn btn-success" type="submit" name="save">
+ <i class="fa fa-check"></i> @Loc["Admin.Common.Save"]
+ </button>
+ <button class="btn btn-success" type="submit" name="save-continue">
+ <i class="fa fa-check-circle"></i> @Loc["Admin.Common.SaveContinue"]
+ </button>
+ <span id="emailAccount-delete" class="btn red">
+ <i class="fa fa-trash-o"></i><span class="d-none d-sm-inline"> @Loc["Admin.Common.Delete"]</span>
+ </span>
+ </div>
+ </div>
+ </div>
+ <div class="x_content form">
+ <partial name="Partials/CreateOrUpdate" model="Model"/>
+ </div>
+ </div>
+ </div>
+ </div>
+</form>
+<admin-delete-confirmation button-id="emailAccount-delete"/>
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/List.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/List.cshtml
new file mode 100644
index 000000000..466531da8
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/List.cshtml
@@ -0,0 +1,71 @@
+@{
+ //page title
+ ViewBag.Title = Loc["Admin.Configuration.EmailAccounts"];
+}
+
+<div class="row">
+ <div class="col-md-12">
+ <div class="x_panel light form-fit">
+ <div class="x_title">
+ <div class="caption">
+ <i class="fa fa-envelope"></i>
+ @Loc["Admin.Configuration.EmailAccounts"]
+ </div>
+ <div class="actions">
+ <a href="@Url.Action("Create", new { area = Constants.AreaStore })" class="btn green">
+ <i class="fa fa-plus"></i><span class="d-none d-sm-inline"> @Loc["Admin.Common.AddNew"] </span>
+ </a>
+ </div>
+ </div>
+ <div class="x_content form">
+ <div id="email-accounts-grid"></div>
+ </div>
+ </div>
+ </div>
+</div>
+<script>
+ $(document).ready(function () {
+ $("#email-accounts-grid").kendoGrid({
+ dataSource: {
+ transport: {
+ read: {
+ url: "@Html.Raw(Url.Action("List", "EmailAccount", new { area = Constants.AreaStore }))",
+ type: "POST",
+ dataType: "json",
+ data: addAntiForgeryToken
+ }
+ },
+ schema: {
+ data: "Data",
+ total: "Total",
+ errors: "Errors"
+ },
+ error: function(e) {
+ display_kendoui_grid_error(e);
+ this.cancelChanges();
+ },
+ serverPaging: true,
+ serverFiltering: true,
+ serverSorting: true
+ },
+ pageable: {
+ refresh: true,
+ numeric: false,
+ previousNext: false,
+ info: false
+ },
+ scrollable: false,
+ columns: [{
+ field: "Email",
+ title: "@Loc["Admin.Configuration.EmailAccounts.Fields.Email"]",
+ template: '<a class="k-link" href="Edit/#=Id#">#=Email#</a>'
+ }, {
+ field: "DisplayName",
+ title: "@Loc["Admin.Configuration.EmailAccounts.Fields.DisplayName"]"
+ }, {
+ field: "Host",
+ title: "@Loc["Admin.Configuration.EmailAccounts.Fields.Host"]"
+ }]
+ });
+ });
+</script>
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/Partials/CreateOrUpdate.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/Partials/CreateOrUpdate.cshtml
new file mode 100644
index 000000000..eebb29bbd
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/EmailAccount/Partials/CreateOrUpdate.cshtml
@@ -0,0 +1,91 @@
+@using Grand.Business.Core.Enums.Messages
+@model EmailAccountModel
+
+<div asp-validation-summary="All"></div>
+<input asp-for="Id" type="hidden"/>
+<input asp-for="StoreId" type="hidden"/>
+<div class="form-horizontal">
+ <div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="Email"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Email"/>
+ <span asp-validation-for="Email"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="DisplayName"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="DisplayName"/>
+ <span asp-validation-for="DisplayName"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Host"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Host"/>
+ <span asp-validation-for="Host"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Port"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Port"/>
+ <span asp-validation-for="Port"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Username"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Username"/>
+ <span asp-validation-for="Username"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Password"/>
+ <div class="col-md-9 col-sm-9">
+ <div class="input-group">
+ <div class="input-icon">
+ <i class="fa fa-lock fa-fw"></i>
+ <admin-input asp-for="Password" autocomplete="off"/>
+ </div>
+ </div>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="UseServerCertificateValidation"/>
+ <div class="col-md-9 col-sm-9">
+ <label class="mt-checkbox mt-checkbox-outline control control-checkbox">
+ <admin-input asp-for="UseServerCertificateValidation"/>
+ <div class="control__indicator"></div>
+ </label>
+ <span asp-validation-for="UseServerCertificateValidation"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="SecureSocketOptionsId"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-select asp-for="SecureSocketOptionsId" asp-items="EnumTranslationService.ToSelectList((SecureSocketOptions)Model.SecureSocketOptionsId)"/>
+ </div>
+ </div>
+ @if (!string.IsNullOrEmpty(Model.Id))
+ {
+ <div class="form-group">
+ <div class="note note-info">
+ @Loc["Admin.Configuration.EmailAccounts.SendTestEmail"]
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="SendTestEmailTo"/>
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="SendTestEmailTo"/>
+ </div>
+ </div>
+ <div class="form-group">
+ <div class="col-md-9 col-sm-9 offset-md-3">
+ <input type="submit" name="sendtestemail" asp-action="SendTestEmail" class="k-button" value="@Loc["Admin.Configuration.EmailAccounts.SendTestEmail.Button"]"/>
+ </div>
+ </div>
+ }
+ </div>
+</div>
diff --git a/src/Web/Grand.Web.Store/Areas/Store/Views/_ViewImports.cshtml b/src/Web/Grand.Web.Store/Areas/Store/Views/_ViewImports.cshtml
index 4d17948f3..bb0768c2b 100644
--- a/src/Web/Grand.Web.Store/Areas/Store/Views/_ViewImports.cshtml
+++ b/src/Web/Grand.Web.Store/Areas/Store/Views/_ViewImports.cshtml
@@ -31,6 +31,7 @@
@using Grand.Web.AdminShared.Models.Cms
@using Grand.Web.AdminShared.Models.News
@using Grand.Web.AdminShared.Models.Blogs
+@using Grand.Web.AdminShared.Models.Messages
@inject LocService Loc
@inject IEnumTranslationService EnumTranslationService
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Store/Controllers/EmailAccountController.cs b/src/Web/Grand.Web.Store/Controllers/EmailAccountController.cs
new file mode 100644
index 000000000..d7d3977bb
--- /dev/null
+++ b/src/Web/Grand.Web.Store/Controllers/EmailAccountController.cs
@@ -0,0 +1,170 @@
+using Grand.Business.Core.Interfaces.Common.Localization;
+using Grand.Business.Core.Interfaces.Messages;
+using Grand.Domain.Messages;
+using Grand.Domain.Permissions;
+using Grand.Infrastructure;
+using Grand.SharedKernel;
+using Grand.Web.AdminShared.Extensions.Mapping;
+using Grand.Web.AdminShared.Interfaces;
+using Grand.Web.AdminShared.Models.Messages;
+using Grand.Web.Common.DataSource;
+using Grand.Web.Common.Filters;
+using Grand.Web.Common.Security.Authorization;
+using Microsoft.AspNetCore.Mvc;
+
+namespace Grand.Web.Store.Controllers;
+
+[PermissionAuthorize(PermissionSystemName.EmailAccounts)]
+public class EmailAccountController(
+ IEmailAccountService emailAccountService,
+ IEmailAccountViewModelService emailAccountViewModelService,
+ ITranslationService translationService,
+ IContextAccessor contextAccessor) : BaseStoreController
+{
+ private string CurrentStoreId => contextAccessor.WorkContext.CurrentCustomer.StaffStoreId;
+
+ public IActionResult List()
+ {
+ return View();
+ }
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.List)]
+ public async Task<IActionResult> List(DataSourceRequest command)
+ {
+ var emailAccounts = await emailAccountService.GetAllEmailAccounts(CurrentStoreId, pageIndex: command.Page - 1, pageSize: command.PageSize);
+ var emailAccountModels = emailAccounts.Select(x => x.ToModel()).ToList();
+
+ var gridModel = new DataSourceResult {
+ Data = emailAccountModels,
+ Total = emailAccounts.TotalCount
+ };
+
+ return Json(gridModel);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ public IActionResult Create()
+ {
+ var model = new EmailAccountModel {
+ Port = 25,
+ StoreId = CurrentStoreId
+ };
+ return View(model);
+ }
+
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ [PermissionAuthorizeAction(PermissionActionName.Create)]
+ public async Task<IActionResult> Create(EmailAccountModel model, bool continueEditing)
+ {
+ // Force the account to belong to the current store
+ model.StoreId = CurrentStoreId;
+
+ if (ModelState.IsValid)
+ {
+ var emailAccount = await emailAccountViewModelService.InsertEmailAccountModel(model);
+ Success(translationService.GetResource("Admin.Configuration.EmailAccounts.Added"));
+ return continueEditing
+ ? RedirectToAction("Edit", new { id = emailAccount.Id })
+ : RedirectToAction("List");
+ }
+
+ return View(model);
+ }
+
+ [PermissionAuthorizeAction(PermissionActionName.Preview)]
+ public async Task<IActionResult> Edit(string id)
+ {
+ var emailAccount = await emailAccountService.GetEmailAccountById(id);
+ if (emailAccount == null || emailAccount.StoreId != CurrentStoreId)
+ return RedirectToAction("List");
+
+ var model = emailAccount.ToModel();
+ return View(model);
+ }
+
+ [HttpPost]
+ [ArgumentNameFilter(KeyName = "save-continue", Argument = "continueEditing")]
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ public async Task<IActionResult> Edit(EmailAccountModel model, bool continueEditing)
+ {
+ var emailAccount = await emailAccountService.GetEmailAccountById(model.Id);
+ if (emailAccount == null || emailAccount.StoreId != CurrentStoreId)
+ return RedirectToAction("List");
+
+ // Prevent moving the account to another store
+ model.StoreId = CurrentStoreId;
+
+ if (ModelState.IsValid)
+ {
+ emailAccount = await emailAccountViewModelService.UpdateEmailAccountModel(emailAccount, model);
+ Success(translationService.GetResource("Admin.Configuration.EmailAccounts.Updated"));
+ return continueEditing
+ ? RedirectToAction("Edit", new { id = emailAccount.Id })
+ : RedirectToAction("List");
+ }
+
+ return View(model);
+ }
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Edit)]
+ public async Task<IActionResult> SendTestEmail(EmailAccountModel model)
+ {
+ var emailAccount = await emailAccountService.GetEmailAccountById(model.Id);
+ if (emailAccount == null || emailAccount.StoreId != CurrentStoreId)
+ return RedirectToAction("List");
+
+ try
+ {
+ if (string.IsNullOrWhiteSpace(model.SendTestEmailTo))
+ throw new GrandException(translationService.GetResource("Admin.Configuration.EmailAccounts.EnterTestEmail"));
+ if (ModelState.IsValid)
+ {
+ await emailAccountViewModelService.SendTestEmail(emailAccount, model);
+ Success(translationService.GetResource("Admin.Configuration.EmailAccounts.SendTestEmail.Success"),
+ false);
+ }
+ else
+ {
+ Error(ModelState);
+ }
+ }
+ catch (Exception exc)
+ {
+ Error(exc.Message);
+ }
+
+ return RedirectToAction("Edit", new { id = model.Id });
+ }
+
+ [HttpPost]
+ [PermissionAuthorizeAction(PermissionActionName.Delete)]
+ public async Task<IActionResult> Delete(string id)
+ {
+ var emailAccount = await emailAccountService.GetEmailAccountById(id);
+ if (emailAccount == null || emailAccount.StoreId != CurrentStoreId)
+ return RedirectToAction("List");
+
+ try
+ {
+ if (ModelState.IsValid)
+ {
+ await emailAccountService.DeleteEmailAccount(emailAccount);
+ Success(translationService.GetResource("Admin.Configuration.EmailAccounts.Deleted"));
+ }
+ else
+ {
+ Error(ModelState);
+ }
+
+ return RedirectToAction("List");
+ }
+ catch (GrandException exc)
+ {
+ Error(exc);
+ return RedirectToAction("Edit", new { id = emailAccount.Id });
+ }
+ }
+}
diff --git a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml
index 3b37fcbdf..743f71b17 100644
Binary files a/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml and b/src/Web/Grand.Web/App_Data/Resources/DefaultLanguage.xml differ