This commit is contained in:
Дмитрий Шиманский
2023-12-19 11:57:19 +03:00
parent 4e43b1631b
commit a5d39384ac
34 changed files with 1825 additions and 79 deletions

37
Pages/Blog.cshtml.cs Normal file
View File

@@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Razor;
using Microsoft.AspNetCore.Mvc.RazorPages;
using yaflay.ru.Models.Tables;
namespace yaflay.ru.Pages
{
public class BlogModel : PageModel
{
public int Id { get; private set; }
//public Comments[] comments { get; set; }
public void OnGet(int? id)
{
Id = id ?? 0;
Page();
//comments = Startup.dbContext.Comments.Where(k => k.postId == Id).OrderBy(k => k.dateTime).Reverse().ToArray();
}
public void OnPost(int? id)
{
Id = id ?? 0;
//comments = Startup.dbContext.Comments.Where(k => k.postId == Id).OrderBy(k => k.dateTime).Reverse().ToArray();
string userEmail = Request.Form["userEmail"];
string commentMessage = Request.Form["commentText"];
if (Id == 0 || commentMessage == null || userEmail == null) { Page(); return; }
Startup.dbContext.Comments.Add(new Comments()
{
Text = commentMessage,
creatorMail = userEmail,
dateTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
postId = Id
});
Startup.dbContext.SaveChanges();
Page();
}
}
}