feat/live-preview #8
@ -457,17 +457,32 @@ public class AdminController : Controller
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> DeletePage()
|
||||
[Route("DeletePage/{id}")]
|
||||
public async Task<IActionResult> DeletePage(string id)
|
||||
{
|
||||
var user = await _authService.GetCurrentUserAsync(User);
|
||||
if (user == null)
|
||||
return RedirectToAction("Login", "Auth");
|
||||
|
||||
var userPage = await _userPageService.GetUserPageAsync(user.Id);
|
||||
if (userPage != null)
|
||||
try
|
||||
{
|
||||
await _userPageService.DeletePageAsync(userPage.Id);
|
||||
TempData["Success"] = "Página excluída com sucesso!";
|
||||
// Verificar se a página existe e pertence ao usuário
|
||||
var page = await _userPageService.GetPageByIdAsync(id);
|
||||
if (page == null || page.UserId != user.Id)
|
||||
{
|
||||
TempData["Error"] = "Página não encontrada ou você não tem permissão para excluí-la.";
|
||||
return RedirectToAction("Dashboard");
|
||||
}
|
||||
|
||||
// Excluir a página
|
||||
await _userPageService.DeletePageAsync(id);
|
||||
|
||||
TempData["Success"] = $"Página '{page.DisplayName}' excluída com sucesso!";
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Erro ao excluir página com ID: {PageId}", id);
|
||||
TempData["Error"] = "Erro ao excluir página. Tente novamente.";
|
||||
}
|
||||
|
||||
return RedirectToAction("Dashboard");
|
||||
|
||||
@ -27,8 +27,17 @@
|
||||
{
|
||||
<div class="col-md-6 col-lg-4 mb-3">
|
||||
<div class="card h-100 @(page.Status == BCards.Web.ViewModels.PageStatus.Active ? "" : "border-warning")">
|
||||
<div class="card-body">
|
||||
<h6 class="card-title">@(page.DisplayName)</h6>
|
||||
<div class="card-body position-relative" style="padding-top: 20px;">
|
||||
<!-- Botão de excluir no canto superior direito -->
|
||||
<button class="btn btn-sm btn-outline-danger position-absolute"
|
||||
style="top: 8px; right: 8px; z-index: 10; padding: 4px 6px;"
|
||||
data-bs-toggle="modal"
|
||||
data-bs-target="#deleteModal-@(page.Id)"
|
||||
title="Excluir página">
|
||||
<i class="fas fa-trash-alt" style="font-size: 11px;"></i>
|
||||
</button>
|
||||
|
||||
<h6 class="card-title" style="padding-right: 35px;">@(page.DisplayName)</h6>
|
||||
<p class="text-muted small mb-2">@(page.Category)/@(page.Slug)</p>
|
||||
|
||||
<div class="mb-2">
|
||||
@ -271,6 +280,46 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Modais de Confirmação para Excluir Páginas -->
|
||||
@foreach (var page in Model.UserPages)
|
||||
{
|
||||
<div class="modal fade" id="deleteModal-@(page.Id)" tabindex="-1" aria-labelledby="deleteModalLabel-@(page.Id)" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-centered">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header border-bottom-0">
|
||||
<h5 class="modal-title" id="deleteModalLabel-@(page.Id)">
|
||||
<i class="fas fa-exclamation-triangle text-warning me-2"></i>
|
||||
Confirmar Exclusão
|
||||
</h5>
|
||||
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="modal-body text-center">
|
||||
<div class="mb-3">
|
||||
<i class="fas fa-trash-alt fa-3x text-danger mb-3"></i>
|
||||
</div>
|
||||
<h6>Tem certeza que deseja excluir a página <strong>"@(page.DisplayName)"</strong>?</h6>
|
||||
<p class="text-muted small mb-0">
|
||||
Esta ação não pode ser desfeita. Todos os dados da página, incluindo estatísticas, serão perdidos permanentemente.
|
||||
</p>
|
||||
</div>
|
||||
<div class="modal-footer border-top-0 justify-content-center">
|
||||
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">
|
||||
<i class="fas fa-times me-2"></i>
|
||||
Cancelar
|
||||
</button>
|
||||
<form method="post" action="@Url.Action("DeletePage", new { id = page.Id })" class="d-inline">
|
||||
@Html.AntiForgeryToken()
|
||||
<button type="submit" class="btn btn-danger">
|
||||
<i class="fas fa-trash-alt me-2"></i>
|
||||
Excluir Página
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@if (TempData["Success"] != null)
|
||||
{
|
||||
<div class="toast-container position-fixed top-0 end-0 p-3">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user