Add caching all data from backend and change getting readme data from page(Index.cshtml) to api(HomeController.cs) with cache readme file

This commit is contained in:
Дмитрий Шиманский
2023-12-24 23:01:57 +03:00
parent 153979cbbd
commit 38c12ca246
4 changed files with 83 additions and 22 deletions

View File

@@ -1,12 +1,15 @@
@page "{id?}"
@model BlogModel
@using yaflay.ru.Models.Tables
@using Newtonsoft.Json
@{
string path = $"{this.Request.Scheme}://{this.Request.Host}";
if (Model.Id != 0)
{
Blogs? Post = Startup.dbContext.Blogs.FirstOrDefault(k => k.Id == Model.Id);
//Blogs? Post = Startup.dbContext.Blogs.FirstOrDefault(k => k.Id == Model.Id);
var request = await Startup.client.GetAsync(path + "/api/Blog/" + Model.Id);
Blogs? Post = JsonConvert.DeserializeObject<Blogs>(request.Content.ReadAsStringAsync().Result);
if (Post == null)
{
ViewData["Title"] = "Blogs";
@@ -66,7 +69,8 @@
else
{
ViewData["Title"] = "Blog";
var allBlogs = Startup.dbContext.Blogs.ToArray();
var request = await Startup.client.GetAsync(path + "/api/Blog/");
Blogs[]? allBlogs = JsonConvert.DeserializeObject<Blogs[]>(request.Content.ReadAsStringAsync().Result);
if (allBlogs.Length == 0)
{
<p>

View File

@@ -7,9 +7,9 @@
<h3 align="left" class="readme" >README.md</h3>
@{
string Github_readme = Startup.client.GetStringAsync(Startup.readmeFile).Result;
string path = $"{this.Request.Scheme}://{this.Request.Host}";
string Github_readme = Startup.client.GetStringAsync($"{path}/api/Index").Result;
<div class="text"> @Html.Raw(Github_readme) </div>
}