#203 add new language

This commit is contained in:
Hamid Reza Mohammadi 2021-09-13 21:45:39 +04:30
parent 8efea91fd2
commit 597d57743d
3 changed files with 36 additions and 5 deletions

View File

@ -1,5 +1,6 @@
@page
@model GanjooRazor.Areas.User.Pages.LanguagesModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
Layout = "_Layout";
ViewData["Title"] = "زبان‌ها و نویسش‌ها";
@ -86,7 +87,7 @@ else
<td>@language.Name</td>
<td>@language.Code</td>
<td>@language.NativeName</td>
<td>(@language.RightToLeft ? "✅" : "⧠")</td>
<td>@($"{(language.RightToLeft ? "✅" : "⧠")}")</td>
<td>@language.Description</td>
<td>
<a role="button" href="/Admin/LanguageEdit/?id=@language.Id" class="actionlink" title="ویرایش">✎</a>

View File

@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using GanjooRazor.Utils;
using Microsoft.AspNetCore.Mvc;
@ -54,6 +52,34 @@ namespace GanjooRazor.Areas.User.Pages
}
return Page();
}
public async Task<IActionResult> OnPostAsync()
{
LastMessage = "";
using (HttpClient secureClient = new HttpClient())
{
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
{
HttpResponseMessage response = await secureClient.PostAsync($"{APIRoot.Url}/api/translations/langugages", new StringContent(JsonConvert.SerializeObject(Language), Encoding.UTF8, "application/json"));
if (!response.IsSuccessStatusCode)
{
LastMessage = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
}
else
{
return await OnGetAsync();
}
}
else
{
LastMessage = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
}
}
return Page();
}
}

View File

@ -22,6 +22,10 @@ namespace RMuseum.Services.Implementation
/// <returns></returns>
public async Task<RServiceResult<GanjoorLanguage>> AddLanguageAsync(GanjoorLanguage lang)
{
lang.Name = lang.Name == null ? lang.Name : lang.Name.Trim();
lang.Code = lang.Code == null ? lang.Code : lang.Code.Trim();
if (string.IsNullOrEmpty(lang.Name) || string.IsNullOrEmpty(lang.Code))
return new RServiceResult<GanjoorLanguage>(null, "ورود کد و نام زبان اجباری است.");
var existing = await _context.GanjoorLanguages.Where(l => l.Name == lang.Name || l.Code == lang.Code).FirstOrDefaultAsync();
if (existing != null)
return new RServiceResult<GanjoorLanguage>(null, "اطلاعات تکراری است.");