diff --git a/GanjooRazor/Pages/Photos.cshtml b/GanjooRazor/Pages/Photos.cshtml new file mode 100644 index 00000000..8f2daacf --- /dev/null +++ b/GanjooRazor/Pages/Photos.cshtml @@ -0,0 +1,60 @@ +@page +@model GanjooRazor.Pages.PhotosModel +@{ + Layout = null; +} + + + + + + + + @Html.Raw(ViewData["Title"]) + + + + + + + + + + + + +
+

+
+
+

+ تصاویر شاعران +

+
+
+
+ +
+
+
+ فهرست شاعران +
+ @foreach (var poet in Model.Poets) + { +
+ @poet.Name + +
+ } +
+
+
+ +
+ + +> \ No newline at end of file diff --git a/GanjooRazor/Pages/Photos.cshtml.cs b/GanjooRazor/Pages/Photos.cshtml.cs new file mode 100644 index 00000000..64066a2f --- /dev/null +++ b/GanjooRazor/Pages/Photos.cshtml.cs @@ -0,0 +1,54 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using RMuseum.Models.Ganjoor.ViewModels; +using System.Collections.Generic; +using System.Net.Http; +using System.Threading.Tasks; + +namespace GanjooRazor.Pages +{ + public class PhotosModel : PageModel + { + public string LastError { get; set; } + + public List Poets { get; set; } + + private async Task> _PreparePoets() + { + var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poets"); + if (!response.IsSuccessStatusCode) + { + LastError = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync()); + return new List(); + } + var poets = JArray.Parse(await response.Content.ReadAsStringAsync()).ToObject>(); + + + foreach (var poet in poets) + { + poet.ImageUrl = $"{APIRoot.InternetUrl}{poet.ImageUrl}"; + } + + return poets; + } + public async Task OnGetAsync() + { + ViewData["Title"] = "تصاویر شاعران گنجور"; + Poets = await _PreparePoets(); + return Page(); + } + + /// + /// HttpClient instance + /// + private readonly HttpClient _httpClient; + + + public PhotosModel(HttpClient httpClient) + { + _httpClient = httpClient; + } + } +} diff --git a/GanjooRazor/appsettings.json b/GanjooRazor/appsettings.json index 53c0d0bc..d390c52a 100644 --- a/GanjooRazor/appsettings.json +++ b/GanjooRazor/appsettings.json @@ -8,8 +8,8 @@ }, "AllowedHosts": "*", "GoogleAnalyticsCode": "", - "APIRoot": "http://localhost:3439", - "GlobalAPIRoot": "http://localhost:3439", + "APIRoot": "https://api.ganjoor.net", + "GlobalAPIRoot": "https://api.ganjoor.net", "SiteUrl": "http://localhost:33081", "AggressiveCacheEnabled": "False", "ReadOnlyMode": "False",