From b469793eb6ef773eec555f2d0b4421f82ea8b5d3 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Thu, 3 Feb 2022 17:56:55 +0330 Subject: [PATCH] docs: #275 moderating suggested lines --- .../User/Pages/SuggestedPoetSpecLines.cshtml | 4 +- .../Pages/SuggestedPoetSpecLines.cshtml.cs | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/GanjooRazor/Areas/User/Pages/SuggestedPoetSpecLines.cshtml b/GanjooRazor/Areas/User/Pages/SuggestedPoetSpecLines.cshtml index f64d6a20..81b018e4 100644 --- a/GanjooRazor/Areas/User/Pages/SuggestedPoetSpecLines.cshtml +++ b/GanjooRazor/Areas/User/Pages/SuggestedPoetSpecLines.cshtml @@ -21,7 +21,7 @@ else شاعر: - @Model.Poet.Nickname + @Model.Poet.Nickname @@ -53,7 +53,7 @@ else diff --git a/GanjooRazor/Areas/User/Pages/SuggestedPoetSpecLines.cshtml.cs b/GanjooRazor/Areas/User/Pages/SuggestedPoetSpecLines.cshtml.cs index 48cdbbf3..b795a393 100644 --- a/GanjooRazor/Areas/User/Pages/SuggestedPoetSpecLines.cshtml.cs +++ b/GanjooRazor/Areas/User/Pages/SuggestedPoetSpecLines.cshtml.cs @@ -6,6 +6,7 @@ using RMuseum.Models.Ganjoor.ViewModels; using RSecurityBackend.Models.Generic; using System.Linq; using System.Net.Http; +using System.Text; using System.Threading.Tasks; namespace GanjooRazor.Areas.User.Pages @@ -86,5 +87,56 @@ namespace GanjooRazor.Areas.User.Pages } } + + public async Task OnPostAsync() + { + + Skip = string.IsNullOrEmpty(Request.Query["skip"]) ? 0 : int.Parse(Request.Query["skip"]); + + if (Request.Form["next"].Count == 1) + { + return Redirect($"/User/SuggestedPoetSpecLines/?skip={Skip + 1}"); + } + + Suggestion.Published = Request.Form["approve"].Count == 1; + + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + if(Suggestion.Published) + { + var putResponse = await secureClient.PutAsync($"{APIRoot.Url}/api/poetspecs", new StringContent(JsonConvert.SerializeObject(Suggestion), Encoding.UTF8, "application/json")); + if (!putResponse.IsSuccessStatusCode) + { + LastError = JsonConvert.DeserializeObject(await putResponse.Content.ReadAsStringAsync()); + } + } + else + { + var deleteResponse = await secureClient.DeleteAsync($"{APIRoot.Url}/api/poetspecs/{Suggestion.Id}"); + if (!deleteResponse.IsSuccessStatusCode) + { + LastError = JsonConvert.DeserializeObject(await deleteResponse.Content.ReadAsStringAsync()); + } + } + + } + else + { + LastError = "لطفا از گنجور خارج و مجددا به آن وارد شوید."; + } + + } + + + if (!string.IsNullOrEmpty(LastError)) + { + return Page(); + } + + return Redirect($"/User/SuggestedPoetSpecLines/?skip={Skip}"); + + } } }
- +