mirror of
https://github.com/yawaflua/yaflay.ru.git
synced 2025-12-11 16:16:26 +02:00
pooko
This commit is contained in:
37
Pages/Blog.cshtml.cs
Normal file
37
Pages/Blog.cshtml.cs
Normal 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();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user