#172 delete page ui
This commit is contained in:
parent
f6939225af
commit
91a920577a
@ -166,3 +166,10 @@
|
||||
<p><a role="button" onclick="rebuildSitemap()" class="actionlink" title="بازسازی نقشهٔ سایت">بازسازی نقشهٔسایت</a></p>
|
||||
|
||||
<p><a role="button" onclick="rebuildStats()" class="actionlink" title="بازسازی صفحات آمار و اوزان عروضی">بازسازی صفحات آمار و اوزان عروضی</a></p>
|
||||
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td><a role="button" href="/Admin/PageDel/?url=@Model.PageInformation.FullUrl" class="actionlink">حذف صفحه</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
40
GanjooRazor/Areas/Admin/Pages/PageDel.cshtml
Normal file
40
GanjooRazor/Areas/Admin/Pages/PageDel.cshtml
Normal file
@ -0,0 +1,40 @@
|
||||
@page
|
||||
@model GanjooRazor.Areas.Admin.Pages.PageDelModel
|
||||
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
|
||||
@{
|
||||
Layout = "_AdminLayout";
|
||||
ViewData["Title"] = "حذف صفحه";
|
||||
}
|
||||
|
||||
<h1>@ViewData["Title"]</h1>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.LastResult))
|
||||
{
|
||||
<p>
|
||||
@Model.LastResult
|
||||
</p>
|
||||
<p>
|
||||
<a role="button" href="/" class="actionlink">برگشت</a>
|
||||
</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<table>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
آیا از حذف @Model.PageInformation.FullTitle اطمینان دارید؟
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<form method="post" action="/Admin/PageDel?id=@Model.PageInformation.Id">
|
||||
<input type="submit" value="بله" />
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<a role="button" href="/Admin/ModifyPage?id=@Model.PageInformation.Id" class="actionlink">خیر / برگشت</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
}
|
||||
|
||||
86
GanjooRazor/Areas/Admin/Pages/PageDel.cshtml.cs
Normal file
86
GanjooRazor/Areas/Admin/Pages/PageDel.cshtml.cs
Normal file
@ -0,0 +1,86 @@
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using GanjooRazor.Utils;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
|
||||
namespace GanjooRazor.Areas.Admin.Pages
|
||||
{
|
||||
[IgnoreAntiforgeryToken(Order = 1001)]
|
||||
public class PageDelModel : PageModel
|
||||
{
|
||||
/// <summary>
|
||||
/// HttpClient instance
|
||||
/// </summary>
|
||||
private readonly HttpClient _httpClient;
|
||||
|
||||
/// <summary>
|
||||
/// memory cache
|
||||
/// </summary>
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
/// <param name="httpClient"></param>
|
||||
/// <param name="memoryCache"></param>
|
||||
public PageDelModel(HttpClient httpClient, IMemoryCache memoryCache)
|
||||
{
|
||||
_httpClient = httpClient;
|
||||
_memoryCache = memoryCache;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// page
|
||||
/// </summary>
|
||||
public GanjoorPageCompleteViewModel PageInformation { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// last result
|
||||
/// </summary>
|
||||
public string LastResult { get; set; }
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
var pageQuery = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/page?url={Request.Query["url"]}");
|
||||
pageQuery.EnsureSuccessStatusCode();
|
||||
|
||||
PageInformation = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject<GanjoorPageCompleteViewModel>();
|
||||
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostAsync()
|
||||
{
|
||||
LastResult = "";
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response);
|
||||
|
||||
HttpResponseMessage response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/ganjoor/page/cache/{Request.Query["id"]}");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
|
||||
response = await secureClient.DeleteAsync($"{APIRoot.Url}/api/ganjoor/page/{Request.Query["id"]}");
|
||||
|
||||
if(!response.IsSuccessStatusCode)
|
||||
{
|
||||
LastResult = await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
response.EnsureSuccessStatusCode();
|
||||
LastResult = "عملیات حذف صفحه انجام شد.";
|
||||
}
|
||||
|
||||
|
||||
return Page();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2775,6 +2775,11 @@ namespace RMuseum.Services.Implementation
|
||||
{
|
||||
return new RServiceResult<bool>(false, "Poem related page can nor be deleted.");
|
||||
}
|
||||
var cat = await _context.GanjoorCategories.Where(c => c.FullUrl == page.FullUrl).FirstOrDefaultAsync();
|
||||
if(cat != null)
|
||||
{
|
||||
return new RServiceResult<bool>(false, "Cat related page can nor be deleted.");
|
||||
}
|
||||
_context.GanjoorPages.Remove(page);
|
||||
await _context.SaveChangesAsync();
|
||||
return new RServiceResult<bool>(true);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user