feat: add persistence and restoration of email template filters in UI and backend
This commit is contained in:
@@ -40,14 +40,24 @@ public class AdminTemplatesController : Controller
|
||||
|
||||
// GET /admin/templates/create
|
||||
[HttpGet("create")]
|
||||
public IActionResult Create()
|
||||
public IActionResult Create([FromQuery] string? serviceNameFilter, [FromQuery] string? keyFilter)
|
||||
{
|
||||
return View("Edit", new EmailTemplateEditViewModel());
|
||||
return View("Edit", new EmailTemplateEditViewModel
|
||||
{
|
||||
ServiceNameFilter = serviceNameFilter,
|
||||
KeyFilter = keyFilter
|
||||
});
|
||||
}
|
||||
|
||||
// GET /admin/templates/{serviceName}/{key}/{languageCode}
|
||||
[HttpGet("{serviceName}/{key}/{languageCode}")]
|
||||
public async Task<IActionResult> Edit(string serviceName, string key, string languageCode, CancellationToken ct)
|
||||
public async Task<IActionResult> Edit(
|
||||
string serviceName,
|
||||
string key,
|
||||
string languageCode,
|
||||
[FromQuery] string? serviceNameFilter,
|
||||
[FromQuery] string? keyFilter,
|
||||
CancellationToken ct)
|
||||
{
|
||||
var result = await _mediator.Send(new GetEmailTemplateQuery(serviceName, key, languageCode), ct);
|
||||
if (!result.IsSuccess || result.Result is null)
|
||||
@@ -63,7 +73,9 @@ public class AdminTemplatesController : Controller
|
||||
Subject = template.Subject,
|
||||
HtmlBody = template.HtmlBody,
|
||||
TextBody = template.TextBody,
|
||||
VariablesJson = JsonSerializer.Serialize(template.Variables)
|
||||
VariablesJson = JsonSerializer.Serialize(template.Variables),
|
||||
ServiceNameFilter = serviceNameFilter,
|
||||
KeyFilter = keyFilter
|
||||
};
|
||||
|
||||
return View(vm);
|
||||
@@ -127,15 +139,21 @@ public class AdminTemplatesController : Controller
|
||||
}
|
||||
}
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
return RedirectToAction(nameof(Index), new { serviceName = model.ServiceNameFilter, key = model.KeyFilter });
|
||||
}
|
||||
|
||||
// POST /admin/templates/{serviceName}/{key}/{languageCode}/delete
|
||||
[HttpPost("{serviceName}/{key}/{languageCode}/delete")]
|
||||
[ValidateAntiForgeryToken]
|
||||
public async Task<IActionResult> Delete(string serviceName, string key, string languageCode, CancellationToken ct)
|
||||
public async Task<IActionResult> Delete(
|
||||
string serviceName,
|
||||
string key,
|
||||
string languageCode,
|
||||
[FromForm] string? serviceNameFilter,
|
||||
[FromForm] string? keyFilter,
|
||||
CancellationToken ct)
|
||||
{
|
||||
await _mediator.Send(new DeleteEmailTemplateCommand(serviceName, key, languageCode), ct);
|
||||
return RedirectToAction(nameof(Index));
|
||||
return RedirectToAction(nameof(Index), new { serviceName = serviceNameFilter, key = keyFilter });
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -25,6 +25,8 @@ public class EmailTemplateEditViewModel
|
||||
|
||||
// JSON array: [{"name":"UserName","required":true}, ...]
|
||||
public string VariablesJson { get; set; } = "[]";
|
||||
public string? ServiceNameFilter { get; set; }
|
||||
public string? KeyFilter { get; set; }
|
||||
|
||||
public bool IsNew => Id == null;
|
||||
public string PageTitle => IsNew ? "Create Email Template" : "Edit Email Template";
|
||||
|
||||
Reference in New Issue
Block a user