#233 saving poet birth place and death place
This commit is contained in:
parent
dce296bba6
commit
9a64a0759c
@ -38,10 +38,51 @@
|
||||
<td>زاده:</td>
|
||||
<td><input asp-for="Poet.BirthYearInLHijri" /> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>تاریخ تولد مستند است:</td>
|
||||
<td><input asp-for="Poet.ValidBirthDate" /> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>زادگاه:</td>
|
||||
<td>
|
||||
<select asp-for="Poet.BirthPlace">
|
||||
@{
|
||||
foreach (var location in Model.Locations)
|
||||
{
|
||||
<option value="@location.Name">@location.Name</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>درگذشته:</td>
|
||||
<td><input asp-for="Poet.DeathYearInLHijri" /> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>تاریخ وفات مستند است:</td>
|
||||
<td><input asp-for="Poet.ValidDeathDate" /> </td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>آرامگاه:</td>
|
||||
<td>
|
||||
<select asp-for="Poet.DeathPlace">
|
||||
@{
|
||||
foreach (var location in Model.Locations)
|
||||
{
|
||||
<option value="@location.Name">@location.Name</option>
|
||||
}
|
||||
}
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
<p>
|
||||
<a href="/Admin/Locations">خاستگاهها</a>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>چسبانی:</td>
|
||||
<td><input asp-for="Poet.PinOrder" /> </td>
|
||||
|
||||
@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Newtonsoft.Json;
|
||||
using RMuseum.Models.Ganjoor;
|
||||
using RMuseum.Models.Ganjoor.ViewModels;
|
||||
using RMuseum.Services.Implementation.ImportedFromDesktopGanjoor;
|
||||
|
||||
@ -27,6 +28,8 @@ namespace GanjooRazor.Areas.Admin.Pages
|
||||
/// </summary>
|
||||
private readonly IMemoryCache _memoryCache;
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// constructor
|
||||
/// </summary>
|
||||
@ -67,6 +70,7 @@ namespace GanjooRazor.Areas.Admin.Pages
|
||||
|
||||
private async Task PreparePoet()
|
||||
{
|
||||
await ReadLocationsAsync();
|
||||
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poet/{Request.Query["id"]}");
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
@ -77,11 +81,54 @@ namespace GanjooRazor.Areas.Admin.Pages
|
||||
Poet = poet.Poet;
|
||||
}
|
||||
|
||||
public List<GanjoorGeoLocation> Locations { get; set; }
|
||||
private async Task ReadLocationsAsync()
|
||||
{
|
||||
LastResult = "";
|
||||
|
||||
using (HttpClient secureClient = new HttpClient())
|
||||
{
|
||||
if (await GanjoorSessionChecker.PrepareClient(secureClient, Request, Response))
|
||||
{
|
||||
var response = await secureClient.GetAsync($"{APIRoot.Url}/api/locations");
|
||||
if (!response.IsSuccessStatusCode)
|
||||
{
|
||||
LastResult = JsonConvert.DeserializeObject<string>(await response.Content.ReadAsStringAsync());
|
||||
return;
|
||||
}
|
||||
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
Locations = new List<GanjoorGeoLocation>();
|
||||
Locations.Add
|
||||
(
|
||||
new GanjoorGeoLocation()
|
||||
{
|
||||
Id = 0,
|
||||
Latitude = 0,
|
||||
Longitude = 0,
|
||||
Name = ""
|
||||
}
|
||||
);
|
||||
|
||||
Locations.AddRange(JsonConvert.DeserializeObject<GanjoorGeoLocation[]>(await response.Content.ReadAsStringAsync()));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LastResult = "لطفا از گنجور خارج و مجددا به آن وارد شوید.";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IActionResult> OnGetAsync()
|
||||
{
|
||||
LastResult = "";
|
||||
if(string.IsNullOrEmpty(Request.Query["id"]))
|
||||
|
||||
if (string.IsNullOrEmpty(Request.Query["id"]))
|
||||
{
|
||||
await ReadLocationsAsync();
|
||||
Poet = new GanjoorPoetViewModel()
|
||||
{
|
||||
Nickname = "",
|
||||
|
||||
@ -98,9 +98,7 @@
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<p>
|
||||
<a href="/Admin/Locations">خاستگاهها</a>
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
<table>
|
||||
|
||||
@ -272,7 +272,7 @@ namespace RMuseum.Services.Implementation
|
||||
(
|
||||
new GanjoorPoetCompleteViewModel()
|
||||
{
|
||||
Poet = await _context.GanjoorPoets.Where(p => p.Id == cat.PoetId)
|
||||
Poet = await _context.GanjoorPoets.Include(p => p.BirthLocation).Include(p => p.DeathLocation).Where(p => p.Id == cat.PoetId)
|
||||
.Select(poet => new GanjoorPoetViewModel()
|
||||
{
|
||||
Id = poet.Id,
|
||||
@ -288,6 +288,8 @@ namespace RMuseum.Services.Implementation
|
||||
ValidBirthDate = poet.ValidBirthDate,
|
||||
ValidDeathDate = poet.ValidDeathDate,
|
||||
PinOrder = poet.PinOrder,
|
||||
BirthPlace = poet.BirthLocation == null ? "" : poet.BirthLocation.Name,
|
||||
DeathPlace = poet.DeathLocation == null ? "" : poet.DeathLocation.Name,
|
||||
}).AsNoTracking().FirstOrDefaultAsync(),
|
||||
Cat = catViewModel
|
||||
}
|
||||
@ -3127,8 +3129,14 @@ namespace RMuseum.Services.Implementation
|
||||
bool publishedChange = dbPoet.Published != poet.Published;
|
||||
dbPoet.Published = poet.Published;
|
||||
dbPoet.BirthYearInLHijri = poet.BirthYearInLHijri;
|
||||
dbPoet.ValidBirthDate = poet.ValidBirthDate;
|
||||
dbPoet.DeathYearInLHijri = poet.DeathYearInLHijri;
|
||||
dbPoet.ValidDeathDate = poet.ValidDeathDate;
|
||||
dbPoet.PinOrder = poet.PinOrder;
|
||||
dbPoet.BirthLocationId = string.IsNullOrEmpty(poet.BirthPlace) ? null
|
||||
: (await _context.GanjoorGeoLocations.Where(l => l.Name == poet.BirthPlace).SingleAsync()).Id;
|
||||
dbPoet.DeathLocationId = string.IsNullOrEmpty(poet.DeathPlace) ? null
|
||||
: (await _context.GanjoorGeoLocations.Where(l => l.Name == poet.DeathPlace).SingleAsync()).Id;
|
||||
_context.GanjoorPoets.Update(dbPoet);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user