From f78204a1fddc35e258dd10841a9c731ae5e881f7 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Tue, 7 Feb 2023 22:15:21 +0330 Subject: [PATCH] docs: #327 models for posting new verse suggestions --- GanjooRazor/Areas/User/Pages/VerseAdd.cshtml | 5 +- .../Areas/User/Pages/VerseAdd.cshtml.cs | 49 +++++++++++++++---- GanjooRazor/Models/NewVersesModel.cs | 23 +++++++++ 3 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 GanjooRazor/Models/NewVersesModel.cs diff --git a/GanjooRazor/Areas/User/Pages/VerseAdd.cshtml b/GanjooRazor/Areas/User/Pages/VerseAdd.cshtml index 32376451..3d54e17b 100644 --- a/GanjooRazor/Areas/User/Pages/VerseAdd.cshtml +++ b/GanjooRazor/Areas/User/Pages/VerseAdd.cshtml @@ -87,7 +87,7 @@ - @if(Model.PageInformation.Poem.Verses.Length == 0) { @@ -107,12 +107,13 @@ - + + diff --git a/GanjooRazor/Areas/User/Pages/VerseAdd.cshtml.cs b/GanjooRazor/Areas/User/Pages/VerseAdd.cshtml.cs index bd66896b..8845e757 100644 --- a/GanjooRazor/Areas/User/Pages/VerseAdd.cshtml.cs +++ b/GanjooRazor/Areas/User/Pages/VerseAdd.cshtml.cs @@ -5,10 +5,14 @@ using Microsoft.Extensions.Configuration; using Newtonsoft.Json.Linq; using Newtonsoft.Json; using RMuseum.Models.Ganjoor.ViewModels; -using System.Collections.Generic; -using System; using System.Net.Http; using System.Threading.Tasks; +using GanjooRazor.Models; +using RMuseum.Models.Ganjoor; +using System.Collections.Generic; +using System; +using Org.BouncyCastle.Asn1.X509; +using System.Text; namespace GanjooRazor.Areas.User.Pages { @@ -48,9 +52,8 @@ namespace GanjooRazor.Areas.User.Pages public bool PostSuccess { get; set; } - public int CoupletIndex { get; set; } - - public string[] NewLines { get; set; } + [BindProperty] + public NewVersesModel NewVerses { get; set; } public GanjoorPageCompleteViewModel PageInformation { get; set; } @@ -85,7 +88,12 @@ namespace GanjooRazor.Areas.User.Pages } PageInformation = JObject.Parse(await pageQuery.Content.ReadAsStringAsync()).ToObject(); - + NewVerses = new NewVersesModel() + { + PoemId = PageInformation.Id, + VOrder = 0, + Lines = "", + }; } else @@ -107,9 +115,32 @@ namespace GanjooRazor.Areas.User.Pages { if (await GanjoorSessionChecker.PrepareClient(_httpClient, Request, Response)) { - //var stringContent = new StringContent(JsonConvert.SerializeObject(Report), Encoding.UTF8, "application/json"); - var methodUrl = $"{APIRoot.Url}/api/audio/errors/report"; - var response = await _httpClient.PostAsync(methodUrl, null /*stringContent*/); + + List vOrderTexts = new List(); + VersePosition versePosition = VersePosition.Right; + foreach (string v in NewVerses.Lines.Split(new char[] { '\r', '\n'}, StringSplitOptions.RemoveEmptyEntries)) + { + vOrderTexts.Add + ( + new GanjoorVerseVOrderText() + { + VORder = NewVerses.VOrder, + Text = v.Replace("ۀ", "هٔ").Replace("ك", "ک"), + NewVerse= true, + VersePosition = versePosition, + } + ); + versePosition = versePosition == VersePosition.Right ? VersePosition.Left : VersePosition.Right; + } + GanjoorPoemCorrectionViewModel correction = new GanjoorPoemCorrectionViewModel() + { + PoemId = NewVerses.PoemId, + VerseOrderText = vOrderTexts.ToArray(), + Note = "پیشنهاد مصرع‌های جاافتاده" + }; + var stringContent = new StringContent(JsonConvert.SerializeObject(correction), Encoding.UTF8, "application/json"); + var methodUrl = $"{APIRoot.Url}/api/ganjoor/poem/correction"; + var response = await _httpClient.PostAsync(methodUrl, stringContent); if (!response.IsSuccessStatusCode) { LastError = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); diff --git a/GanjooRazor/Models/NewVersesModel.cs b/GanjooRazor/Models/NewVersesModel.cs new file mode 100644 index 00000000..fefc35ba --- /dev/null +++ b/GanjooRazor/Models/NewVersesModel.cs @@ -0,0 +1,23 @@ +namespace GanjooRazor.Models +{ + /// + /// new verses model + /// + public class NewVersesModel + { + /// + /// Poem Id + /// + public int PoemId { get; set; } + + /// + /// Verse Order + /// + public int VOrder { get; set; } + + /// + /// new lines + /// + public string Lines { get; set;} + } +}