#203 saving a translation
This commit is contained in:
parent
78b9fa1aa4
commit
82f4e24d69
@ -1,7 +1,6 @@
|
||||
@page
|
||||
@model GanjooRazor.Areas.User.Pages.TranslateModel
|
||||
@using DNTPersianUtils.Core
|
||||
@using System.Linq
|
||||
@{
|
||||
Layout = "_Layout";
|
||||
ViewData["Title"] = "برگردان / نویسش";
|
||||
@ -125,7 +124,7 @@ else
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
توضیح این ویرایش:
|
||||
یادداشت این ویرایش:
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@ -149,7 +148,47 @@ else
|
||||
|
||||
<tr>
|
||||
<td>
|
||||
<a role="button" id="savecorrections" style="cursor:pointer;width:100%;color:white;background-color:green;display:block" onclick="savePoemCorrections(@Model.PageInformation.Poem.Id, @Model.PageInformation.Poem.Verses.Length)">ذخیره</a>
|
||||
<script>
|
||||
function savePoemTranslation(id, verseCount, langid) {
|
||||
var translations = [];
|
||||
for (var i = 0; i <= verseCount; i++) {
|
||||
var newElementName = '#id-' + i.toString();
|
||||
translations.push(i.toString() + 'TextSeparator' + $(newElementName).text());
|
||||
}
|
||||
|
||||
$('#savetranslation').hide();
|
||||
$('#saving').text('در حال ذخیره ...');
|
||||
|
||||
var url = '?handler=SendPoemTranslation';
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: url,
|
||||
data: {
|
||||
poemid: id,
|
||||
langid: langid,
|
||||
translations: translations,
|
||||
published: $('#published').is(":checked"),
|
||||
note: $('#description').val()
|
||||
|
||||
},
|
||||
success: function () {
|
||||
location.reload(true);
|
||||
},
|
||||
error: function (e) {
|
||||
if (e.responseText == null)
|
||||
alert(e);
|
||||
else
|
||||
alert(e.responseText);
|
||||
$('#savetranslation').show();
|
||||
$('#saving').text('');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
<a role="button" id="savetranslation" style="cursor:pointer;width:100%;color:white;background-color:green;display:block" onclick="savePoemTranslation(@Model.PageInformation.Poem.Id, @Model.PageInformation.Poem.Verses.Length, @Model.Translation.Language.Id)">ذخیره</a>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
@ -32,6 +32,11 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
/// </summary>
|
||||
public GanjoorPoemTranslationViewModel Translation { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// user info
|
||||
/// </summary>
|
||||
public PublicRAppUser UserInfo { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// fatal error
|
||||
/// </summary>
|
||||
@ -80,10 +85,7 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
return -1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// user info
|
||||
/// </summary>
|
||||
public PublicRAppUser UserInfo { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// get
|
||||
@ -155,63 +157,50 @@ namespace GanjooRazor.Areas.User.Pages
|
||||
return Page();
|
||||
}
|
||||
|
||||
public async Task<IActionResult> 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<IActionResult> OnPostSendPoemCorrectionsAsync(int poemid, string[] verseOrderText, string rhythm, string note)
|
||||
public async Task<IActionResult> OnPostSendPoemTranslationAsync(int poemid, int langid, string[] translations, bool published, string note)
|
||||
{
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
string title = null;
|
||||
List<GanjoorVerseVOrderText> vOrderTexts = new List<GanjoorVerseVOrderText>();
|
||||
foreach (string v in verseOrderText)
|
||||
List<GanjoorVerseTranslationViewModel> verses = new List<GanjoorVerseTranslationViewModel>();
|
||||
foreach (string v in translations)
|
||||
{
|
||||
var vParts = v.Split("TextSeparator", System.StringSplitOptions.RemoveEmptyEntries);
|
||||
int vOrder = int.Parse(vParts[0]);
|
||||
if (vOrder == 0)
|
||||
if (vOrder == 0 && vParts.Length > 1)
|
||||
title = vParts[1];
|
||||
else
|
||||
{
|
||||
vOrderTexts.Add
|
||||
verses.Add
|
||||
(
|
||||
new GanjoorVerseVOrderText()
|
||||
new GanjoorVerseTranslationViewModel()
|
||||
{
|
||||
VORder = vOrder,
|
||||
Text = vParts[1]
|
||||
Verse = new GanjoorVerseViewModel() { VOrder = vOrder },
|
||||
TText = vParts.Length > 1 ? vParts[1] : null
|
||||
}
|
||||
);
|
||||
);;
|
||||
}
|
||||
}
|
||||
|
||||
if (title == null && vOrderTexts.Count == 0 && rhythm == null)
|
||||
return new BadRequestObjectResult("شما هیچ تغییری در متن ندادهاید!");
|
||||
if (string.IsNullOrEmpty(title) && verses.Where(v => !string.IsNullOrEmpty(v.TText) ).FirstOrDefault() == null)
|
||||
return new BadRequestObjectResult("شما هیچ متنی را وارد نکردهاید!");
|
||||
|
||||
GanjoorPoemCorrectionViewModel correction = new GanjoorPoemCorrectionViewModel()
|
||||
var translation = new GanjoorPoemTranslationViewModel()
|
||||
{
|
||||
Language = new GanjoorLanguage() { Id = langid },
|
||||
PoemId = poemid,
|
||||
Title = title,
|
||||
VerseOrderText = vOrderTexts.ToArray(),
|
||||
Rhythm = rhythm,
|
||||
Note = note
|
||||
Published = published,
|
||||
Description = note,
|
||||
TranslatedVerses = verses.ToArray()
|
||||
};
|
||||
|
||||
HttpResponseMessage response = await secureClient.PostAsync(
|
||||
$"{APIRoot.Url}/api/ganjoor/poem/correction",
|
||||
new StringContent(JsonConvert.SerializeObject(correction),
|
||||
$"{APIRoot.Url}/api/translations/poem",
|
||||
new StringContent(JsonConvert.SerializeObject(translation),
|
||||
Encoding.UTF8,
|
||||
"application/json"));
|
||||
if (!response.IsSuccessStatusCode)
|
||||
|
||||
@ -5,6 +5,10 @@
|
||||
/// </summary>
|
||||
public class GanjoorPoemTranslationViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// id
|
||||
/// </summary>
|
||||
public int Id { get; set; }
|
||||
/// <summary>
|
||||
/// language
|
||||
/// </summary>
|
||||
|
||||
@ -6193,6 +6193,11 @@
|
||||
poem translation view model
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemTranslationViewModel.Id">
|
||||
<summary>
|
||||
id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoemTranslationViewModel.Language">
|
||||
<summary>
|
||||
language
|
||||
|
||||
@ -54,7 +54,7 @@ namespace RMuseum.Services
|
||||
/// <param name="translation"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
Task<RServiceResult<bool>> AddPoemTranslation(Guid userId, GanjoorPoemTranslationViewModel translation);
|
||||
Task<RServiceResult<GanjoorPoemTranslationViewModel>> AddPoemTranslation(Guid userId, GanjoorPoemTranslationViewModel translation);
|
||||
|
||||
/// <summary>
|
||||
/// get translations for a poem
|
||||
|
||||
@ -133,7 +133,7 @@ namespace RMuseum.Services.Implementation
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="translation"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<RServiceResult<bool>> AddPoemTranslation(Guid userId, GanjoorPoemTranslationViewModel translation)
|
||||
public async Task<RServiceResult<GanjoorPoemTranslationViewModel>> AddPoemTranslation(Guid userId, GanjoorPoemTranslationViewModel translation)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -160,7 +160,7 @@ namespace RMuseum.Services.Implementation
|
||||
var verses = await _context.GanjoorVerses.Where(v => v.PoemId == translation.PoemId).ToListAsync();
|
||||
foreach (var translatedVerse in translation.TranslatedVerses)
|
||||
{
|
||||
var verse = verses.Where(v => v.VOrder == translatedVerse.Verse.Id).Single();
|
||||
var verse = verses.Where(v => v.VOrder == translatedVerse.Verse.VOrder).Single();
|
||||
dbTranslation.Verses
|
||||
.Add(
|
||||
new GanjoorVerseTranslation()
|
||||
@ -174,11 +174,13 @@ namespace RMuseum.Services.Implementation
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return new RServiceResult<bool>(true);
|
||||
translation.Id = dbTranslation.Id;
|
||||
|
||||
return new RServiceResult<GanjoorPoemTranslationViewModel>(translation);
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return new RServiceResult<bool>(false, exp.ToString());
|
||||
return new RServiceResult<GanjoorPoemTranslationViewModel>(null, exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -202,6 +204,7 @@ namespace RMuseum.Services.Implementation
|
||||
(
|
||||
new GanjoorPoemTranslationViewModel()
|
||||
{
|
||||
Id = dbTranslation.Id,
|
||||
Language = dbTranslation.Language,
|
||||
PoemId = poemId,
|
||||
Title = dbTranslation.Title,
|
||||
@ -254,6 +257,7 @@ namespace RMuseum.Services.Implementation
|
||||
res.Add(
|
||||
new GanjoorPoemTranslationViewModel()
|
||||
{
|
||||
Id = dbTranslation.Id,
|
||||
Language = dbTranslation.Language,
|
||||
PoemId = poemId,
|
||||
Title = dbTranslation == null ? null : dbTranslation.Title,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user