diff --git a/GanjooRazor/Areas/User/Pages/Editor.cshtml b/GanjooRazor/Areas/User/Pages/Editor.cshtml index 1092e4f5..b1feb094 100644 --- a/GanjooRazor/Areas/User/Pages/Editor.cshtml +++ b/GanjooRazor/Areas/User/Pages/Editor.cshtml @@ -3,31 +3,47 @@ @using DNTPersianUtils.Core @{ Layout = "_Layout"; - ViewData["Title"] = "ویرایشگر شعر"; + ViewData["Title"] = "ویرایشگر"; + await GanjooRazor.Utils.GanjoorSessionChecker.ApplyPermissionsToViewData(Request, Response, ViewData); }

@ViewData["Title"]

- @if (!string.IsNullOrEmpty(Model.FatalError)) {

@Model.FatalError

} else { +

@Model.PageInformation.FullTitle

+ + @if (Model.PageInformation.Poem.Previous != null) + { +

ویرایش شعر قبل

+ } + @if (Model.PageInformation.Poem.Next != null) + { +

ویرایش شعر بعد

+ } + if (Model.MyLastEdit != null) { - + + + + + + @if (Model.MyLastEdit.Title != null) { } @@ -35,10 +51,10 @@ else { } @@ -64,6 +80,12 @@ else } + + + +
ویرایشهای منویرایشهای بررسی نشدهٔ من
متن اولیهتغییرات من
-

@Model.MyLastEdit.Title

+

@Model.MyLastEdit.OriginalTitle

-

@Model.MyLastEdit.OriginalTitle

+

@Model.MyLastEdit.Title

-

@Model.MyLastEdit.Rhythm

+

@Model.MyLastEdit.OriginalRhythm

-

@Model.MyLastEdit.OriginalRhythm

+

@Model.MyLastEdit.Rhythm

+ انصراف و حذف این ویرایش +
} @@ -90,7 +112,19 @@ else - + @if (Model.MyLastEdit != null && Model.MyLastEdit.Title != null) + { + + + } + else + { + + } @@ -137,7 +171,19 @@ else - + @if (Model.MyLastEdit != null && Model.MyLastEdit.VerseOrderText != null && Model.MyLastEdit.VerseOrderText.Where(v => v.VORder == verse.VOrder).Any()) + { + + + } + else + { + + } @@ -170,7 +216,15 @@ else - + @if (Model.MyLastEdit != null && Model.MyLastEdit.Rhythm != null) + { + + + } + else + { + + } @if (Model.Rhythms != null) @foreach (var rhythm in Model.Rhythms) @@ -188,16 +242,39 @@ else - + @if (Model.MyLastEdit != null && !string.IsNullOrEmpty(Model.MyLastEdit.Note)) + { + + } + else + { + + } - ذخیره + ذخیره + +

 

+ + + @if (Model.PageInformation.Poem.Previous != null) + { + + ویرایش شعر قبل + + } + @if (Model.PageInformation.Poem.Next != null) + { + + ویرایش شعر بعد + + } } \ No newline at end of file diff --git a/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs b/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs index b0592399..584a9775 100644 --- a/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs +++ b/GanjooRazor/Areas/User/Pages/Editor.cshtml.cs @@ -114,6 +114,21 @@ namespace GanjooRazor.Areas.User.Pages return Page(); } + public async Task OnPostDeletePoemCorrectionsAsync(int poemid) + { + using (HttpClient secureClient = new HttpClient()) + { + if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response)) + { + HttpResponseMessage response = await secureClient.DeleteAsync( + $"{APIRoot.Url}/api/ganjoor/poem/correction/{poemid}"); + response.EnsureSuccessStatusCode(); + return new OkObjectResult(true); + } + } + return new BadRequestObjectResult("لطفا از گنجور خارج و مجددا به آن وارد شوید."); + } + public async Task OnPostSendPoemCorrectionsAsync(int poemid, string[] verseOrderText, string rhythm, string note) { using (HttpClient secureClient = new HttpClient()) diff --git a/GanjooRazor/Pages/Shared/_Layout.cshtml b/GanjooRazor/Pages/Shared/_Layout.cshtml index 01aac90e..b53371bd 100644 --- a/GanjooRazor/Pages/Shared/_Layout.cshtml +++ b/GanjooRazor/Pages/Shared/_Layout.cshtml @@ -13,6 +13,7 @@ + @@ -201,7 +202,33 @@ result.appendChild(fragment); } + function deletePoemCorrections(id) { + if (!confirm('آیا از حذف تغییرات پیشنهادی اطمینان دارید؟')) + return; + + $('#deletecorrections').hide(); + $('#saving').text('در حال ذخیره ...'); + + var url = '?handler=DeletePoemCorrections'; + + $.ajax({ + type: "POST", + url: url, + data: { + poemid: id, + }, + error: function () { + alert('خطا رخ داد.') + }, + success: function () { + location.reload(true); + }, + + }); + } + function savePoemCorrections(id, verseCount) { + var verseOrderText = []; for (var i = 0; i <= verseCount; i++) { var oldElementName = '#original-' + i.toString(); @@ -218,6 +245,9 @@ } } + $('#savecorrections').hide(); + $('#saving').text('در حال ذخیره ...'); + var rhythm_new = $('#rhythm-new').val(); if (rhythm_new == $('#rhythm-old').text()) { rhythm_new = null; @@ -239,7 +269,9 @@ location.reload(true); }, error: function (e) { - alert(e) + alert(e); + $('#savecorrections').show(); + $('#saving').text(''); } }); @@ -309,8 +341,8 @@ - - + + diff --git a/RMuseum/Controllers/GanjoorController.cs b/RMuseum/Controllers/GanjoorController.cs index d2d1b539..ff3609ee 100644 --- a/RMuseum/Controllers/GanjoorController.cs +++ b/RMuseum/Controllers/GanjoorController.cs @@ -808,6 +808,29 @@ namespace RMuseum.Controllers return Ok(res.Result); } + /// + /// delete unreviewed user corrections for a poem + /// + /// + /// + [HttpDelete] + [Route("poem/correction/{id}")] + [Authorize] + [ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(GanjoorPoemCorrectionViewModel))] + [ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))] + [ProducesResponseType((int)HttpStatusCode.NotFound)] + public async Task DeletePoemCorrections(int id) + { + var userId = + new Guid(User.Claims.FirstOrDefault(c => c.Type == "UserId").Value); + + var res = + await _ganjoorService.DeletePoemCorrections(userId, id); + if (!string.IsNullOrEmpty(res.ExceptionString)) + return BadRequest(res.ExceptionString); + return Ok(); + } + /// /// returns last unreviewed correction from the user for a poem /// diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index d035bbb4..64f0299d 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -921,6 +921,13 @@ + + + delete unreviewed user corrections for a poem + + + + returns last unreviewed correction from the user for a poem @@ -7643,6 +7650,14 @@ + + + delete unreviewed user corrections for a poem + + + + + next unreviewed track @@ -9213,6 +9228,14 @@ + + + delete unreviewed user corrections for a poem + + + + + send poem correction diff --git a/RMuseum/Services/IGanjoorService.cs b/RMuseum/Services/IGanjoorService.cs index 5450a899..868018b9 100644 --- a/RMuseum/Services/IGanjoorService.cs +++ b/RMuseum/Services/IGanjoorService.cs @@ -152,6 +152,14 @@ namespace RMuseum.Services /// Task> GetLastUnreviewedUserCorrectionForPoem(Guid userId, int poemId); + /// + /// delete unreviewed user corrections for a poem + /// + /// + /// + /// + Task> DeletePoemCorrections(Guid userId, int poemId); + /// /// next unreviewed track /// diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index f6fecae3..0386c056 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -1298,6 +1298,29 @@ namespace RMuseum.Services.Implementation ); } + /// + /// delete unreviewed user corrections for a poem + /// + /// + /// + /// + public async Task> DeletePoemCorrections(Guid userId, int poemId) + { + var preCorrections = await _context.GanjoorPoemCorrections.Include(c => c.VerseOrderText) + .Where(c => c.UserId == userId && c.PoemId == poemId && c.Result == CorrectionReviewResult.NotReviewed) + .ToListAsync(); + if (preCorrections.Count > 0) + { + foreach (var preCorrection in preCorrections) + { + preCorrection.VerseOrderText.Clear(); + } + _context.GanjoorPoemCorrections.RemoveRange(preCorrections); + await _context.SaveChangesAsync(); + } + return new RServiceResult(true); + } + /// /// send poem correction /// @@ -1305,6 +1328,10 @@ namespace RMuseum.Services.Implementation /// public async Task> SuggestPoemCorrection(GanjoorPoemCorrectionViewModel correction) { + var preCorrections = await _context.GanjoorPoemCorrections.Include(c => c.VerseOrderText) + .Where(c => c.UserId == correction.UserId && c.PoemId == correction.PoemId && c.Result == CorrectionReviewResult.NotReviewed) + .ToListAsync(); + var poem = (await GetPoemById(correction.PoemId, false, false, true, false, false, false, false, true, false)).Result; foreach (var verse in correction.VerseOrderText) { @@ -1328,6 +1355,16 @@ namespace RMuseum.Services.Implementation await _context.SaveChangesAsync(); correction.Id = dbCorrection.Id; + if(preCorrections.Count > 0) + { + foreach (var preCorrection in preCorrections) + { + preCorrection.VerseOrderText.Clear(); + } + _context.GanjoorPoemCorrections.RemoveRange(preCorrections); + await _context.SaveChangesAsync(); + } + return new RServiceResult(correction); }