mirror of
https://github.com/yawaflua/yaflay.ru.git
synced 2025-12-09 20:19:32 +02:00
38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Razor;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using yawaflua.ru.Models.Tables;
|
|
|
|
namespace yawaflua.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();
|
|
|
|
}
|
|
}
|
|
}
|