70 lines
2.2 KiB
C#
70 lines
2.2 KiB
C#
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Newtonsoft.Json;
|
|
using RMuseum.Models.Ganjoor.ViewModels;
|
|
using RMuseum.Models.GanjoorAudio.ViewModels;
|
|
|
|
namespace GanjooRazor.Pages
|
|
{
|
|
public class AudioClipModel : PageModel
|
|
{
|
|
/// <summary>
|
|
/// HttpClient instance
|
|
/// </summary>
|
|
private readonly HttpClient _httpClient;
|
|
|
|
/// <summary>
|
|
/// configration file reader (appsettings.json)
|
|
/// </summary>
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
|
/// <summary>
|
|
/// constructor
|
|
/// </summary>
|
|
/// <param name="httpClient"></param>
|
|
/// <param name="configuration"></param>
|
|
public AudioClipModel(HttpClient httpClient, IConfiguration configuration)
|
|
{
|
|
_httpClient = httpClient;
|
|
_configuration = configuration;
|
|
}
|
|
|
|
/// <summary>
|
|
/// recitation
|
|
/// </summary>
|
|
public PublicRecitationViewModel Recitation { get; set; }
|
|
|
|
/// <summary>
|
|
/// poem
|
|
/// </summary>
|
|
public GanjoorPoemCompleteViewModel Poem { get; set; }
|
|
|
|
public async Task<IActionResult> OnGetAsync()
|
|
{
|
|
if (!ModelState.IsValid)
|
|
{
|
|
return BadRequest();
|
|
}
|
|
|
|
ViewData["GoogleAnalyticsCode"] = _configuration["GoogleAnalyticsCode"];
|
|
|
|
var response = await _httpClient.GetAsync($"{APIRoot.Url}/api/audio/published/{Request.Query["a"]}");
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
Recitation = JsonConvert.DeserializeObject<PublicRecitationViewModel>(await response.Content.ReadAsStringAsync());
|
|
|
|
var responsePoem = await _httpClient.GetAsync($"{APIRoot.Url}/api/ganjoor/poem/{Recitation.PoemId}?verseDetails=true&catInfo=true&rhymes=false&recitations=false&images=false&songs=false&comments=false&navigation=false");
|
|
responsePoem.EnsureSuccessStatusCode();
|
|
|
|
Poem = JsonConvert.DeserializeObject<GanjoorPoemCompleteViewModel>(await responsePoem.Content.ReadAsStringAsync());
|
|
|
|
return Page();
|
|
|
|
}
|
|
}
|
|
}
|