diff --git a/GanjooRazor/Areas/Admin/Pages/SectionDel.cshtml b/GanjooRazor/Areas/Admin/Pages/SectionDel.cshtml new file mode 100644 index 00000000..abd4f713 --- /dev/null +++ b/GanjooRazor/Areas/Admin/Pages/SectionDel.cshtml @@ -0,0 +1,40 @@ +@page +@model GanjooRazor.Areas.Admin.Pages.SectionDelModel +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers +@{ + Layout = "_AdminLayout"; + ViewData["Title"] = "حذف قطعه"; +} + +

@ViewData["Title"]

+ +@if (!string.IsNullOrEmpty(Model.LastResult)) +{ +

+ @Model.LastResult +

+

+ برگشت +

+} +else +{ + + + + + + + + +
+ آیا از حذف این قطعه اطمینان دارید؟ +
+
+ +
+
+ خیر / برگشت +
+} + diff --git a/GanjooRazor/Areas/Admin/Pages/SectionDel.cshtml.cs b/GanjooRazor/Areas/Admin/Pages/SectionDel.cshtml.cs new file mode 100644 index 00000000..7427f38c --- /dev/null +++ b/GanjooRazor/Areas/Admin/Pages/SectionDel.cshtml.cs @@ -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 + { + /// + /// HttpClient instance + /// + private readonly HttpClient _httpClient; + + /// + /// constructor + /// + /// + public SectionDelModel(HttpClient httpClient) + { + _httpClient = httpClient; + } + + /// + /// last result + /// + public string LastResult { get; set; } + + + public IActionResult OnGet() + { + if (string.IsNullOrEmpty(Request.Cookies["Token"])) + return Redirect("/"); + + LastResult = ""; + + return Page(); + } + + public async Task 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(await response.Content.ReadAsStringAsync()); + return Page(); + } + + LastResult = "ÞØÚå ÍÐÝ ÔÏ."; + + return Page(); + + } + } + } +} diff --git a/GanjooRazor/Areas/User/Pages/Section.cshtml b/GanjooRazor/Areas/User/Pages/Section.cshtml index ea789207..e399b206 100644 --- a/GanjooRazor/Areas/User/Pages/Section.cshtml +++ b/GanjooRazor/Areas/User/Pages/Section.cshtml @@ -460,5 +460,12 @@ else } + + @if (Model.CanEdit) + { + + حذف قطعه + + } } diff --git a/GanjooRazor/Areas/User/Pages/Section.cshtml.cs b/GanjooRazor/Areas/User/Pages/Section.cshtml.cs index fc14caf0..8ec028e4 100644 --- a/GanjooRazor/Areas/User/Pages/Section.cshtml.cs +++ b/GanjooRazor/Areas/User/Pages/Section.cshtml.cs @@ -102,12 +102,18 @@ namespace GanjooRazor.Areas.User.Pages public GanjoorPoemSection Previous { get; set; } + /// + /// can edit + /// + public bool CanEdit { get; set; } + public async Task OnGetAsync() { if (string.IsNullOrEmpty(Request.Cookies["Token"])) return Redirect("/"); FatalError = ""; + CanEdit = Request.Cookies["CanEdit"] == "True"; using (HttpClient secureClient = new HttpClient()) { diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs index 4a30f14d..7111467c 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PoemSections.cs @@ -776,6 +776,9 @@ namespace RMuseum.Services.Implementation _context.UpdateRange(connextedVerses); _context.Remove(section); + await _context.SaveChangesAsync(); + + return new RServiceResult(true); } catch (Exception e)