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

@@ -10,6 +10,29 @@
<link rel="stylesheet" href="~/css/editor/editor-main.css" asp-append-version="true"/>
}
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-body div-main-body">
<div class="form-inline div-tools">
<label id="lblBoardName" class="control-label"></label>
<button class="btn btn-sm btn-primary" onclick="openModalSelectBoard();"><i class="fas fa-mouse-pointer"></i>&nbsp;Izberi oglasno desko</button>
</div>
<div class="div-pages">
<div data-idpage="-100" class="page-active">
<h5>Ime page</h5>
<small>20 sekund</small>
</div>
<div class="add-page" onclick="openModalBoardAddNewPage();">
<i class="fas fa-plus fa-2x"></i>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-12">
<div class="card">
@@ -59,7 +82,34 @@
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" onclick="saveModalEditNote();">Save changes</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="divModalAddEditPage" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 id="titleModalAddEditPage" class="modal-title">List</h5>
<button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<input class="input-hidden" id="inpModalAddEditPageId" />
<div class="form-group">
<label class="control-label">Ime</label>
<input id="inpModalAddEditPageName" type="text" class="form-control"/>
</div>
<div class="form-group">
<label class="control-label">Trajanje</label>
<input id="inpModalAddEditPageDuration" type="number" class="form-control"/>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" onclick="boardAddNewPage();">Shrani</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>

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 });
}
}
}