86 lines
2.1 KiB
C#
86 lines
2.1 KiB
C#
using MemberCenter.Application.Abstractions;
|
|
using MemberCenter.Web.Models.Admin;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace MemberCenter.Web.Controllers.Admin;
|
|
|
|
[Authorize(Policy = "Admin")]
|
|
[Route("admin/newsletter-lists")]
|
|
public class NewsletterListsController : Controller
|
|
{
|
|
private readonly INewsletterListService _listService;
|
|
|
|
public NewsletterListsController(INewsletterListService listService)
|
|
{
|
|
_listService = listService;
|
|
}
|
|
|
|
[HttpGet("")]
|
|
public async Task<IActionResult> Index()
|
|
{
|
|
var lists = await _listService.ListAsync();
|
|
return View(lists);
|
|
}
|
|
|
|
[HttpGet("create")]
|
|
public IActionResult Create()
|
|
{
|
|
return View(new NewsletterListFormViewModel());
|
|
}
|
|
|
|
[HttpPost("create")]
|
|
public async Task<IActionResult> Create(NewsletterListFormViewModel model)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return View(model);
|
|
}
|
|
|
|
await _listService.CreateAsync(model.TenantId, model.Name, model.Status);
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
[HttpGet("edit/{id:guid}")]
|
|
public async Task<IActionResult> Edit(Guid id)
|
|
{
|
|
var list = await _listService.GetAsync(id);
|
|
if (list is null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return View(new NewsletterListFormViewModel
|
|
{
|
|
Id = list.Id,
|
|
TenantId = list.TenantId,
|
|
Name = list.Name,
|
|
Status = list.Status
|
|
});
|
|
}
|
|
|
|
[HttpPost("edit/{id:guid}")]
|
|
public async Task<IActionResult> Edit(Guid id, NewsletterListFormViewModel model)
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return View(model);
|
|
}
|
|
|
|
var updated = await _listService.UpdateAsync(id, model.TenantId, model.Name, model.Status);
|
|
if (updated is null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
[HttpPost("delete/{id:guid}")]
|
|
public async Task<IActionResult> Delete(Guid id)
|
|
{
|
|
await _listService.DeleteAsync(id);
|
|
return RedirectToAction("Index");
|
|
}
|
|
}
|