#412 undo a correction
This commit is contained in:
parent
967928c843
commit
bcf2084774
@ -20,7 +20,7 @@ else
|
||||
{
|
||||
@if (Model.Profile != null)
|
||||
{
|
||||
|
||||
|
||||
<div id="profile">
|
||||
<p>
|
||||
<a href="/hashieha?userId=@Model.Profile.Id">@Model.Profile.NickName</a>
|
||||
@ -30,7 +30,7 @@ else
|
||||
<a href="@Model.Profile.Website">🌐</a>
|
||||
}
|
||||
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
@if (!string.IsNullOrEmpty(Model.Profile.Bio))
|
||||
@ -48,7 +48,34 @@ else
|
||||
</p>
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
<script>
|
||||
function rollBackCorrection(correctionId){
|
||||
if (!confirm('ویرایش معکوس ایجاد شود؟')) {
|
||||
return;
|
||||
}
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: '?handler=RollBackCorrection',
|
||||
data: {
|
||||
correctionId: correctionId,
|
||||
},
|
||||
success: function () {
|
||||
alert('انجام شد.');
|
||||
location.reload(true);
|
||||
},
|
||||
error: function (e) {
|
||||
if (e.responseText == null)
|
||||
alert(e);
|
||||
else
|
||||
alert(e.responseText);
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
}
|
||||
|
||||
@if (Model.Corrections.Count == 0)
|
||||
@ -544,12 +571,12 @@ else
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@if(correction.Reviewed && Model.CanEdit)
|
||||
@if (correction.Reviewed)
|
||||
{
|
||||
<tr>
|
||||
<td colspan="3">
|
||||
<td colspan="3">
|
||||
<a role="button" style="cursor:pointer;width:100%;color:white;background-color:orange;display:block" onclick="rollBackCorrection(@correction.Id)">برگشت به وضعیت قبل از این ویرایش</a>
|
||||
</td>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using DNTPersianUtils.Core;
|
||||
using GanjooRazor.Utils;
|
||||
@ -190,5 +191,78 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
}
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnPostRollBackCorrectionAsync(int correctionId)
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
var correctionResponse = await secureClient.GetAsync($"{APIRoot.Url}/api/ganjoor/correction/{correctionId}");
|
||||
if (!correctionResponse.IsSuccessStatusCode)
|
||||
{
|
||||
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await correctionResponse.Content.ReadAsStringAsync()));
|
||||
}
|
||||
|
||||
var currentCorrection = JsonConvert.DeserializeObject<GanjoorPoemCorrectionViewModel>(await correctionResponse.Content.ReadAsStringAsync());
|
||||
GanjoorPoemCorrectionViewModel correction = new GanjoorPoemCorrectionViewModel();
|
||||
correction.PoemId = currentCorrection.PoemId;
|
||||
if (currentCorrection.Title != null)
|
||||
{
|
||||
correction.OriginalTitle = currentCorrection.Title;
|
||||
correction.Title = currentCorrection.OriginalTitle;
|
||||
}
|
||||
|
||||
if (currentCorrection.VerseOrderText != null)
|
||||
{
|
||||
List<GanjoorVerseVOrderText> vOrderTexts = new List<GanjoorVerseVOrderText>();
|
||||
foreach (var verseOrderText in currentCorrection.VerseOrderText)
|
||||
{
|
||||
if (
|
||||
verseOrderText.Result == CorrectionReviewResult.Approved
|
||||
||
|
||||
verseOrderText.VersePositionResult == CorrectionReviewResult.Approved
|
||||
||
|
||||
verseOrderText.LanguageReviewResult == CorrectionReviewResult.Approved
|
||||
||
|
||||
verseOrderText.SummaryReviewResult == CorrectionReviewResult.Approved
|
||||
)
|
||||
{
|
||||
vOrderTexts.Add(
|
||||
new GanjoorVerseVOrderText()
|
||||
{
|
||||
VORder = verseOrderText.VORder,
|
||||
OriginalText = verseOrderText.Text,
|
||||
Text = verseOrderText.OriginalText,
|
||||
VersePosition = verseOrderText.VersePositionResult == CorrectionReviewResult.Approved && verseOrderText.VersePosition != null ? verseOrderText.OriginalVersePosition : null,
|
||||
OriginalVersePosition = verseOrderText.VersePositionResult == CorrectionReviewResult.Approved && verseOrderText.VersePosition != null ? verseOrderText.VersePosition : null,
|
||||
LanguageId = verseOrderText.LanguageReviewResult == CorrectionReviewResult.Approved && verseOrderText.LanguageId != null ? verseOrderText.OriginalLanguageId : null,
|
||||
OriginalLanguageId = verseOrderText.LanguageReviewResult == CorrectionReviewResult.Approved && verseOrderText.LanguageId != null ? verseOrderText.LanguageId : null,
|
||||
CoupletIndex = verseOrderText.CoupletIndex,
|
||||
CoupletSummary = verseOrderText.SummaryReviewResult == CorrectionReviewResult.Approved && verseOrderText.CoupletSummary != null ? verseOrderText.OriginalCoupletSummary : null,
|
||||
OriginalCoupletSummary = verseOrderText.SummaryReviewResult == CorrectionReviewResult.Approved && verseOrderText.CoupletSummary != null ? verseOrderText.CoupletSummary : null,
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
HttpResponseMessage response = await secureClient.PostAsync(
|
||||
$"{APIRoot.Url}/api/ganjoor/poem/correction",
|
||||
new StringContent(JsonConvert.SerializeObject(correction),
|
||||
Encoding.UTF8,
|
||||
"application/json"));
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
return new BadRequestObjectResult(JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync()));
|
||||
}
|
||||
|
||||
|
||||
return new OkObjectResult(true);
|
||||
}
|
||||
}
|
||||
return new BadRequestObjectResult("لطفاً از گنجور خارج و مجددا به آن وارد شوید.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user