docs: #364 deleting poem sections bug fix and UI

This commit is contained in:
Hamid Reza Mohammadi 2023-02-16 14:59:22 +03:30
parent 91f976b438
commit f207b5b988
5 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,40 @@
@page
@model GanjooRazor.Areas.Admin.Pages.SectionDelModel
@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="/User/Section?poemId=@(Request.Query["poemId"])&index=@(Request.Query["sectionIndex"])" class="actionlink">برگشت</a>
</p>
}
else
{
<table>
<tr>
<td colspan="2">
آیا از حذف این قطعه اطمینان دارید؟
</td>
</tr>
<tr>
<td>
<form method="post">
<input type="submit" value="بله" />
</form>
</td>
<td>
<a role="button" href="/User/Section?poemId=@(Request.Query["poemId"])&index=@(Request.Query["sectionIndex"])" class="actionlink">خیر / برگشت</a>
</td>
</tr>
</table>
}

View File

@ -0,0 +1,65 @@
using GanjooRazor.Utils;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using System.Net.Http;
using System.Threading.Tasks;
namespace GanjooRazor.Areas.Admin.Pages
{
[IgnoreAntiforgeryToken(Order = 1001)]
public class SectionDelModel : PageModel
{
/// <summary>
/// HttpClient instance
/// </summary>
private readonly HttpClient _httpClient;
/// <summary>
/// constructor
/// </summary>
/// <param name="httpClient"></param>
public SectionDelModel(HttpClient httpClient)
{
_httpClient = httpClient;
}
/// <summary>
/// last result
/// </summary>
public string LastResult { get; set; }
public IActionResult OnGet()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
LastResult = "";
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/section/{Request.Query["poemId"]}/{Request.Query["sectionIndex"]}");
if (!response.IsSuccessStatusCode)
{
LastResult = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
return Page();
}
LastResult = "ÞØÚå ÍÐÝ ÔÏ.";
return Page();
}
}
}
}

View File

@ -460,5 +460,12 @@ else
</td>
</tr>
}
@if (Model.CanEdit)
{
<tr>
<td><a role="button" href="/Admin/SectionDel?poemId=@Model.PageInformation.Id&sectionIndex=@Model.PoemSection.Index" class="pagebutton">حذف قطعه</a></td>
</tr>
}
</table>
}

View File

@ -102,12 +102,18 @@ namespace GanjooRazor.Areas.User.Pages
public GanjoorPoemSection Previous { get; set; }
/// <summary>
/// can edit
/// </summary>
public bool CanEdit { get; set; }
public async Task<IActionResult> OnGetAsync()
{
if (string.IsNullOrEmpty(Request.Cookies["Token"]))
return Redirect("/");
FatalError = "";
CanEdit = Request.Cookies["CanEdit"] == "True";
using (HttpClient secureClient = new HttpClient())
{

View File

@ -776,6 +776,9 @@ namespace RMuseum.Services.Implementation
_context.UpdateRange(connextedVerses);
_context.Remove(section);
await _context.SaveChangesAsync();
return new RServiceResult<bool>(true);
}
catch (Exception e)