barve, shranjevanje

This commit is contained in:
David Štaleker
2024-02-28 20:04:20 +01:00
parent dc24cb22a6
commit 26a78d5188
11 changed files with 1239 additions and 79 deletions

View File

@@ -4,6 +4,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using ZpcBulletinBoard.Data;
using ZpcBulletinBoard.Models.Editor;
using System.Linq;
namespace ZpcBulletinBoard.Pages.Editor
{
@@ -43,7 +44,10 @@ namespace ZpcBulletinBoard.Pages.Editor
{
var page = context.BulletinBoardPage.Include(x => x.Notes)
.FirstOrDefault(x => x.IdBulletinBoardPage == id);
foreach (var note in page.Notes)
{
note.BulletinBoardPage = null;
}
return page == null
? new JsonResult(new { successful = false, error = $"Page with ID {id} not exists!" })
: new JsonResult(new { successful = true, error = $"", page });
@@ -55,7 +59,6 @@ namespace ZpcBulletinBoard.Pages.Editor
if (page.IdBulletinBoardPage <= 0)
{
context.BulletinBoardPage.Add(page);
context.SaveChanges();
}
else
{
@@ -65,11 +68,46 @@ namespace ZpcBulletinBoard.Pages.Editor
tmpPage.Name = page.Name;
tmpPage.Duration = page.Duration;
context.SaveChanges();
}
context.SaveChanges();
return new JsonResult(new { successful = true, error = $"", page });
}
public IActionResult OnPostNotes(int idBulletinBoardPage, List<Note> notes)
{
//Pobrisem katerih ni vec
var notesToDelete = context.Notes.Where(x => x.IdBulletinBoardPage == idBulletinBoardPage
&& !notes.Select(y => y.IdNote).Contains(x.IdNote)).ToList();
notesToDelete.ForEach(x => context.Notes.Remove(x));
foreach (var note in notes)
{
if (note.IdNote <= 0)
{
note.IdNote = default;
context.Notes.Add(note);
}
else
{
var tmpNote = context.Notes.FirstOrDefault(x => x.IdNote == note.IdNote);
if (tmpNote == null)
continue;
// return new JsonResult(new { successful = false, error = $"Page with ID {page.IdBulletinBoardPage} not exists!", page });
tmpNote.X = note.X;
tmpNote.Y = note.Y;
tmpNote.Width = note.Width;
tmpNote.Height = note.Height;
tmpNote.Content = note.Content;
tmpNote.Zindex = note.Zindex;
tmpNote.ColorClass = note.ColorClass;
}
}
context.SaveChanges();
return new JsonResult(new { successful = true, error = "" });
}
}
}