#233 using poet groups instead of poets for map

This commit is contained in:
Hamid Reza Mohammadi 2021-11-03 19:23:15 +03:30
parent 7c5a9b7c3d
commit 80f234c6b1
2 changed files with 21 additions and 14 deletions

View File

@ -49,8 +49,9 @@
var oms = new OverlappingMarkerSpiderfier(map, { keepSpiderfied: false });
var poets = @(Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.PoetsWithBirthPlaces, Newtonsoft.Json.Formatting.Indented)));
var poetsgroups = @(Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model.PoetGroupsWithBirthPlaces, Newtonsoft.Json.Formatting.Indented)));
var poets = poetsgroups[0].Poets;
for (var i = 0; i < poets.length; i++) {
var poet = poets[i];
var icon = L.icon({

View File

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
@ -13,26 +13,23 @@ namespace GanjooRazor.Pages
{
public class MapModel : PageModel
{
/// <summary>
/// Poets
/// </summary>
public List<GanjoorPoetViewModel> PoetsWithBirthPlaces { get; set; }
private async Task _PreparePoets()
private async Task<List<GanjoorPoetViewModel>> _PreparePoets()
{
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poets");
response.EnsureSuccessStatusCode();
var poets = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorPoetViewModel>>();
PoetsWithBirthPlaces = poets.Where(p => !string.IsNullOrEmpty(p.BirthPlace)).ToList();
var poetsWithBirthPlaces = poets.Where(p => !string.IsNullOrEmpty(p.BirthPlace)).ToList();
foreach (var poet in PoetsWithBirthPlaces)
foreach (var poet in poetsWithBirthPlaces)
{
poet.ImageUrl = $"{APIRoot.InternetUrl}{poet.ImageUrl}";
}
return poetsWithBirthPlaces;
}
public List<GanjoorCenturyViewModel> PoetGroupsWithBirthPlaces { get; set; }
private async Task _PreparePoetGroups()
@ -41,10 +38,20 @@ namespace GanjooRazor.Pages
response.EnsureSuccessStatusCode();
var poetGroups = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject<List<GanjoorCenturyViewModel>>();
PoetGroupsWithBirthPlaces = new List<GanjoorCenturyViewModel>();
PoetGroupsWithBirthPlaces.Add
(
new GanjoorCenturyViewModel()
{
Id = 0,
Name = "همهٔ اعصار",
ShowInTimeLine = true,
Poets = await _PreparePoets()
}
);
foreach (var poetGroup in poetGroups)
{
poetGroup.Poets = poetGroup.Poets.Where(p => !string.IsNullOrEmpty(p.BirthPlace)).ToList();
if(poetGroup.Poets.Count > 0)
if (poetGroup.Poets.Count > 0)
{
PoetGroupsWithBirthPlaces.Add(poetGroup);
}
@ -53,7 +60,6 @@ namespace GanjooRazor.Pages
public async Task<IActionResult> OnGetAsync()
{
await _PreparePoets();
await _PreparePoetGroups();
return Page();
}
@ -68,7 +74,7 @@ namespace GanjooRazor.Pages
/// </summary>
private readonly IMemoryCache _memoryCache;
public MapModel(IConfiguration configuration,
HttpClient httpClient,
IMemoryCache memoryCache