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.

Admin panel - Drop CustomerModel from several controller actions

support60e4a425de8e
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/Edit.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/Edit.cshtml
index 76d24deeb..d320b9806 100644
--- a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/Edit.cshtml
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/Edit.cshtml
@@ -42,72 +42,4 @@
</form>
<admin-delete-confirmation button-id="customer-delete"/>
-<div id="sendemail-window" style="display:none;">
- <form asp-area="@Constants.AreaAdmin" asp-controller="Customer" asp-action="SendEmail" method="post" asp-route-id="Id">
-
- <input type="hidden" asp-for="Id" id="sendemail_customerId" />
- <div class="form-horizontal">
- <div class="form-body">
- <div class="form-group">
- <admin-label asp-for="SendEmail.Subject" />
- <div class="col-md-9 col-sm-9">
- <admin-input asp-for="SendEmail.Subject" />
- <span asp-validation-for="SendEmail.Subject"></span>
- </div>
- </div>
- <div class="form-group">
- <admin-label asp-for="SendEmail.Body" />
- <div class="col-md-9 col-sm-9">
- <admin-textarea asp-for="SendEmail.Body"></admin-textarea>
- <span asp-validation-for="SendEmail.Body"></span>
- </div>
- </div>
- <div class="form-group">
- <admin-label asp-for="SendEmail.SendImmediately" />
- <div class="col-md-9 col-sm-9">
- <admin-input asp-for="SendEmail.SendImmediately" />
- <span asp-validation-for="SendEmail.SendImmediately"></span>
- </div>
- </div>
- <div class="form-group" id="pnl-send-date">
- <admin-label asp-for="SendEmail.DontSendBeforeDate" />
- <div class="col-md-9 col-sm-9">
- <admin-input asp-for="SendEmail.DontSendBeforeDate" />
- <span asp-validation-for="SendEmail.DontSendBeforeDate"></span>
- </div>
- </div>
- </div>
- <div class="form-actions">
- <div class="offset-md-3 offset-sm-3 col-md-6 col-sm-6">
- <button type="submit" class="k-button"><span class="k-icon k-i-email"></span>&nbsp;@Loc["Admin.Customers.Customers.SendEmail"]</button>
- </div>
- </div>
- </div>
- </form>
-</div>
-<script>
- $(document).ready(function () {
- $("#sendemail").click(function (e) {
- e.preventDefault();
- var window = $("#sendemail-window");
- if (!window.data("kendoWindow")) {
- window.kendoWindow({
- modal: true,
- width: "650px",
- title: "@Loc["Admin.Customers.Customers.SendEmail"]",
- actions: ["Close"]
- });
- }
- window.data('kendoWindow').center().open();
- });
-
-
- //timing of send email section
- $("#pnl-send-date").hide();
-
- $("#sendemail-window .check-box").click(function () {
- $("#pnl-send-date").toggle();
- });
-
- });
-</script>
+<partial name="Partials/SendEmail" model="Model.SendEmail" />
\ No newline at end of file
diff --git a/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/Partials/SendEmail.cshtml b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/Partials/SendEmail.cshtml
new file mode 100644
index 000000000..df5a2be62
--- /dev/null
+++ b/src/Web/Grand.Web.Admin/Areas/Admin/Views/Customer/Partials/SendEmail.cshtml
@@ -0,0 +1,70 @@
+@model CustomerModel.SendEmailModel
+
+<div id="sendemail-window" style="display:none;">
+ <form asp-area="@Constants.AreaAdmin" asp-controller="Customer" asp-action="SendEmail" method="post" asp-route-id="Id">
+ <input type="hidden" asp-for="Id" id="sendemail_customerId" />
+ <div class="form-horizontal">
+ <div class="form-body">
+ <div class="form-group">
+ <admin-label asp-for="Subject" />
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="Subject" />
+ <span asp-validation-for="Subject"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="Body" />
+ <div class="col-md-9 col-sm-9">
+ <admin-textarea asp-for="Body"></admin-textarea>
+ <span asp-validation-for="Body"></span>
+ </div>
+ </div>
+ <div class="form-group">
+ <admin-label asp-for="SendImmediately" />
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="SendImmediately" />
+ <span asp-validation-for="SendImmediately"></span>
+ </div>
+ </div>
+ <div class="form-group" id="pnl-send-date">
+ <admin-label asp-for="DontSendBeforeDate" />
+ <div class="col-md-9 col-sm-9">
+ <admin-input asp-for="DontSendBeforeDate" />
+ <span asp-validation-for="DontSendBeforeDate"></span>
+ </div>
+ </div>
+ </div>
+ <div class="form-actions">
+ <div class="offset-md-3 offset-sm-3 col-md-6 col-sm-6">
+ <button type="submit" class="k-button"><span class="k-icon k-i-email"></span>&nbsp;@Loc["Admin.Customers.Customers.SendEmail"]</button>
+ </div>
+ </div>
+ </div>
+ </form>
+</div>
+<script>
+ $(document).ready(function () {
+ $("#sendemail").click(function (e) {
+ e.preventDefault();
+ var window = $("#sendemail-window");
+ if (!window.data("kendoWindow")) {
+ window.kendoWindow({
+ modal: true,
+ width: "650px",
+ title: "@Loc["Admin.Customers.Customers.SendEmail"]",
+ actions: ["Close"]
+ });
+ }
+ window.data('kendoWindow').center().open();
+ });
+
+
+ //timing of send email section
+ $("#pnl-send-date").hide();
+
+ $("#sendemail-window .check-box").click(function () {
+ $("#pnl-send-date").toggle();
+ });
+
+ });
+</script>
diff --git a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs b/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
index 41927c72f..2e0d9bd6c 100644
--- a/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
+++ b/src/Web/Grand.Web.Admin/Controllers/CustomerController.cs
@@ -301,9 +301,9 @@ namespace Grand.Web.Admin.Controllers
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
- public async Task<IActionResult> MarkVatNumberAsValid(CustomerModel model)
+ public async Task<IActionResult> MarkVatNumberAsValid(string id)
{
- var customer = await _customerService.GetCustomerById(model.Id);
+ var customer = await _customerService.GetCustomerById(id);
if (customer == null || customer.Deleted || await CheckSalesManager(customer))
//No customer found with the specified id
return RedirectToAction("List");
@@ -317,9 +317,9 @@ namespace Grand.Web.Admin.Controllers
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
- public async Task<IActionResult> MarkVatNumberAsInvalid(CustomerModel model)
+ public async Task<IActionResult> MarkVatNumberAsInvalid(string id)
{
- var customer = await _customerService.GetCustomerById(model.Id);
+ var customer = await _customerService.GetCustomerById(id);
if (customer == null || customer.Deleted || await CheckSalesManager(customer))
//No customer found with the specified id
return RedirectToAction("List");
@@ -333,9 +333,9 @@ namespace Grand.Web.Admin.Controllers
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
- public async Task<IActionResult> RemoveAffiliate(CustomerModel model)
+ public async Task<IActionResult> RemoveAffiliate(string id)
{
- var customer = await _customerService.GetCustomerById(model.Id);
+ var customer = await _customerService.GetCustomerById(id);
if (customer == null || customer.Deleted || await CheckSalesManager(customer))
//No customer found with the specified id
return RedirectToAction("List");
@@ -414,9 +414,9 @@ namespace Grand.Web.Admin.Controllers
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
- public async Task<IActionResult> SendWelcomeMessage(CustomerModel model)
+ public async Task<IActionResult> SendWelcomeMessage(string id)
{
- var customer = await _customerService.GetCustomerById(model.Id);
+ var customer = await _customerService.GetCustomerById(id);
if (customer == null || customer.Deleted || await CheckSalesManager(customer))
//No customer found with the specified id
return RedirectToAction("List");
@@ -430,9 +430,9 @@ namespace Grand.Web.Admin.Controllers
[PermissionAuthorizeAction(PermissionActionName.Edit)]
[HttpPost]
- public async Task<IActionResult> ReSendActivationMessage(CustomerModel model)
+ public async Task<IActionResult> ReSendActivationMessage(string id)
{
- var customer = await _customerService.GetCustomerById(model.Id);
+ var customer = await _customerService.GetCustomerById(id);
if (customer == null || customer.Deleted || await CheckSalesManager(customer))
//No customer found with the specified id
return RedirectToAction("List");
@@ -447,7 +447,7 @@ namespace Grand.Web.Admin.Controllers
}
[PermissionAuthorizeAction(PermissionActionName.Edit)]
- public async Task<IActionResult> SendEmail(CustomerModel model)
+ public async Task<IActionResult> SendEmail(CustomerModel.SendEmailModel model)
{
var customer = await _customerService.GetCustomerById(model.Id);
if (customer == null || customer.Deleted || await CheckSalesManager(customer))
@@ -460,12 +460,12 @@ namespace Grand.Web.Admin.Controllers
throw new GrandException("Customer email is empty");
if (!CommonHelper.IsValidEmail(customer.Email))
throw new GrandException("Customer email is not valid");
- if (string.IsNullOrWhiteSpace(model.SendEmail.Subject))
+ if (string.IsNullOrWhiteSpace(model.Subject))
throw new GrandException("Email subject is empty");
- if (string.IsNullOrWhiteSpace(model.SendEmail.Body))
+ if (string.IsNullOrWhiteSpace(model.Body))
throw new GrandException("Email body is empty");
- await _customerViewModelService.SendEmail(customer, model.SendEmail);
+ await _customerViewModelService.SendEmail(customer, model);
Success(_translationService.GetResource("Admin.Customers.Customers.SendEmail.Queued"));
}
diff --git a/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.cs b/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.cs
index 29585e5ce..b1921f8a3 100644
--- a/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.cs
+++ b/src/Web/Grand.Web.Admin/Models/Customers/CustomerModel.cs
@@ -267,6 +267,8 @@ namespace Grand.Web.Admin.Models.Customers
public class SendEmailModel : BaseModel
{
+ public string Id { get; set; }
+
[GrandResourceDisplayName("Admin.Customers.Customers.SendEmail.Subject")]
public string Subject { get; set; }