#445 GanjoorPoetViewModel + Tajik fields

This commit is contained in:
Hamid Reza Mohammadi 2024-07-20 16:42:05 +03:30
parent f7e17b8a6d
commit 8fd1be44c2
6 changed files with 44 additions and 61 deletions

View File

@ -100,6 +100,16 @@
/// </summary>
public double DeathPlaceLongitude { get; set; }
/// <summary>
/// tajik nick name
/// </summary>
public string TajikNickName { get; set; }
/// <summary>
/// additional descripion or note in Tajik
/// </summary>
public string TajikDescription { get; set; }
public override string ToString()
{
return Nickname;

View File

@ -12030,6 +12030,16 @@
death place longitude
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoetViewModel.TajikNickName">
<summary>
tajik nick name
</summary>
</member>
<member name="P:RMuseum.Models.Ganjoor.ViewModels.GanjoorPoetViewModel.TajikDescription">
<summary>
additional descripion or note in Tajik
</summary>
</member>
<member name="T:RMuseum.Models.Ganjoor.ViewModels.GanjoorPostReportCommentViewModel">
<summary>
report comment view model

View File

@ -80,6 +80,8 @@ namespace RMuseum.Services.Implementation
DeathPlaceLatitude = poet.DeathLocation == null ? 0 : poet.DeathLocation.Latitude,
DeathPlaceLongitude = poet.DeathLocation == null ? 0 : poet.DeathLocation.Longitude,
PinOrder = poet.PinOrder,
TajikNickName = poet.TajikNickName,
TajikDescription = poet.TajikDescription,
}
)
.AsNoTracking()
@ -471,6 +473,8 @@ namespace RMuseum.Services.Implementation
DeathPlace = poet.DeathLocation == null ? "" : poet.DeathLocation.Name,
DeathPlaceLatitude = poet.DeathLocation == null ? 0 : poet.DeathLocation.Latitude,
DeathPlaceLongitude = poet.DeathLocation == null ? 0 : poet.DeathLocation.Longitude,
TajikNickName = poet.TajikNickName,
TajikDescription = poet.TajikDescription,
}).AsNoTracking().FirstOrDefaultAsync(),
Cat = catViewModel
}
@ -631,6 +635,8 @@ namespace RMuseum.Services.Implementation
ValidDeathDate = poet.ValidDeathDate,
DeathYearInLHijri = poet.DeathYearInLHijri,
PinOrder = poet.PinOrder,
TajikNickName = poet.TajikNickName,
TajikDescription = poet.TajikDescription,
}
)
.AsNoTracking().SingleAsync();

View File

@ -1,13 +1,27 @@
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
ViewData["Title"] = "Ганҷур";
}
@if(!string.IsNullOrEmpty(Model.LastError))
{
@Html.Raw(Model.LastError)
return;
}
@if(Model.Poets == null)
{
<p>
Хато дар дарёфт феҳристи суханварон
</p>
return;
}
<div class="text-center">
<h1 class="display-4">Ганҷур</h1>
@foreach(var poet in Model.Poets)
{
<p><a href="@poet.FullUrl">@poet.Nickname</a></p>
<p><a href="@poet.FullUrl">@poet.TajikNickName</a></p>
}
</div>

View File

@ -10,7 +10,7 @@ namespace TajikGanjoor.Pages
{
public class IndexModel : PageModel
{
public List<GanjoorPoetViewModel> Poets { get; set; }
public List<GanjoorPoetViewModel>? Poets { get; set; }
public async Task<IActionResult> OnGetAsync()
{
@ -24,11 +24,6 @@ namespace TajikGanjoor.Pages
return Page();
}
foreach (var poet in Poets)
{
poet.Nickname = TajikTransilerator.Transilerate(poet.Nickname);
}
return Page();
}
@ -63,7 +58,7 @@ namespace TajikGanjoor.Pages
return true;
}
public string LastError { get; set; }
public string? LastError { get; set; }
public bool AggressiveCacheEnabled
{

View File

@ -1,52 +0,0 @@
using System.Net;
using System.Text;
using System.Web;
namespace TajikGanjoor
{
public static class TajikTransilerator
{
public static string Transilerate(string input)
{
string txt = "ctl00%24ContentPlaceHolder2%24ScriptManager1=ctl00%24ContentPlaceHolder2%24UpdatePanel1%7Cctl00%24ContentPlaceHolder2%24btnConvert&__EVENTTARGET=&__EVENTARGUMENT=&ctl00%24ContentPlaceHolder2%24txtPersian=%D8%AD%D8%B3%D9%86&ctl00%24ContentPlaceHolder2%24txtSuggest=&__VIEWSTATE=FJBM71Nf2Mzx%2BAjVP0LDLRQCvG%2FugjscaiM7gw%2FgpSEoehbsWEMsC7oirmYVtQOUfi54eqgLZgamFYJBb1aYL%2F14dcixVbv1QXAiL9MM6etgOF2vr6c%2FWRXq%2FGJG2cHi2RB8WjgX%2FCUwp2H%2F3DmyVIY4l24XTb8Y0Onu8oNXM5dbfxAs&__VIEWSTATEGENERATOR=82B657B9&__EVENTVALIDATION=y6DlG61vZjyA%2B6t19Hfyomarliwfg8r%2FDo7E%2BXbLHgNT0mxwLpAsjMso%2FrXEsKomZQZRKOwE1s8PwY1aJVUDoiWEfnlLe9HNFndoQBA5UwX0LIHzVZez4spR534XJhre0pFd2PrCeJj35v9clTYrdBfiZ1hvyXAggj5iYlCWl56DVz8JfmNSXlsN2Wirik5DsTGXsw%3D%3D&__ASYNCPOST=true&ctl00%24ContentPlaceHolder2%24btnConvert=%D8%A8%D8%B1%DA%AF%D8%B1%D8%AF%D8%A7%D9%86";
txt = txt.Replace("%D8%AD%D8%B3%D9%86", HttpUtility.UrlEncode(input));
HttpWebRequest request = HttpWebRequest.Create("http://persian-tajik.ir/farsitotajiki.aspx") as HttpWebRequest;
ASCIIEncoding ascii = new ASCIIEncoding();
byte[] postBytes = ascii.GetBytes(txt);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postBytes.Length;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
// add post data to request
Stream postStream = request.GetRequestStream();
postStream.Write(postBytes, 0, postBytes.Length);
postStream.Flush();
postStream.Close();
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
int startIndex = responseString.IndexOf("ContentPlaceHolder2_txtCirlic");
if (startIndex != -1)
{
int startDivIndex = responseString.IndexOf(">", startIndex);
if (startDivIndex != -1)
{
startDivIndex++;
}
int endDivIndex = responseString.IndexOf("</div>", startDivIndex);
return responseString.Substring(startDivIndex, endDivIndex - startDivIndex).Replace("<span style=\"color: red\">", "").Replace("</span>", "").Trim();
}
return input;
}
}
}