This commit is contained in:
David Štaleker
2024-02-28 11:17:12 +01:00
parent e92956075f
commit dc24cb22a6
5 changed files with 249 additions and 5 deletions

View File

@@ -1,8 +1,9 @@
using System.Data.Entity;
using Microsoft.EntityFrameworkCore;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using ZpcBulletinBoard.Data;
using ZpcBulletinBoard.Models.Editor;
namespace ZpcBulletinBoard.Pages.Editor
{
@@ -16,6 +17,7 @@ namespace ZpcBulletinBoard.Pages.Editor
}
//Get
public IActionResult OnGetBoards()
{
var boards= context.BulletinBoards.ToList();
@@ -27,8 +29,47 @@ namespace ZpcBulletinBoard.Pages.Editor
{
var board = context.BulletinBoards.Include(x => x.Pages)
.FirstOrDefault(x => x.IdBulletinBoard == id);
//Ce je ntre board pole json vrze vn
foreach (var bulletinBoardPage in board.Pages)
{
bulletinBoardPage.BulletinBoard = null;
}
return board == null
? new JsonResult(new { successful = false, error = $"Board with ID {id} not exists!"})
: new JsonResult(new { successful = true, error = $"", board });
}
return new JsonResult(new { successful = true, error = $"", board });
public IActionResult OnGetPage(int id)
{
var page = context.BulletinBoardPage.Include(x => x.Notes)
.FirstOrDefault(x => x.IdBulletinBoardPage == id);
return page == null
? new JsonResult(new { successful = false, error = $"Page with ID {id} not exists!" })
: new JsonResult(new { successful = true, error = $"", page });
}
//Post
public IActionResult OnPostBoardPage(BulletinBoardPage page)
{
if (page.IdBulletinBoardPage <= 0)
{
context.BulletinBoardPage.Add(page);
context.SaveChanges();
}
else
{
var tmpPage = context.BulletinBoardPage.FirstOrDefault(x => x.IdBulletinBoardPage == page.IdBulletinBoardPage);
if (tmpPage == null)
return new JsonResult(new { successful = false, error = $"Page with ID {page.IdBulletinBoardPage} not exists!", page });
tmpPage.Name = page.Name;
tmpPage.Duration = page.Duration;
context.SaveChanges();
}
return new JsonResult(new { successful = true, error = $"", page });
}
}
}