This commit is contained in:
David Štaleker
2024-03-11 06:46:32 +01:00
parent 4ea291622a
commit 172626c8ee
9 changed files with 367 additions and 124 deletions

View File

@@ -48,7 +48,7 @@ namespace ZpcBulletinBoard.Pages.BoardsLinks
var order = 1;
var links = context.BulletinBoardPageLinks.Where(x => x.IdBulletinBoardFk == idBoard).ToList();
if (links.Any())
order = links.Max(x => x.IdLink) + 1;
order = links.Max(x => x.Order) + 1;
var link = new BulletinBoardPageLink
{
@@ -68,5 +68,58 @@ namespace ZpcBulletinBoard.Pages.BoardsLinks
return new JsonResult(new { successful = true, error = $"", link });
}
public IActionResult OnPostSwapLinkOrder(int idLinkStart, int idLinkEnd)
{
var linkStart = context.BulletinBoardPageLinks.FirstOrDefault(x => x.IdLink == idLinkStart);
var linkEnd = context.BulletinBoardPageLinks.FirstOrDefault(x => x.IdLink == idLinkEnd);
if (linkStart == null)
return new JsonResult(new { successful = false, error = $"Link with ID {idLinkStart} not exists!" });
if (linkEnd == null)
return new JsonResult(new { successful = false, error = $"Link with ID {idLinkEnd} not exists!" });
(linkStart.Order, linkEnd.Order) = (linkEnd.Order, linkStart.Order);
context.SaveChanges();
return new JsonResult(new { successful = true, error = $"", linkStart, linkEnd });
}
public IActionResult OnPostLinkDuration(int idLink, int duration)
{
var link = context.BulletinBoardPageLinks.FirstOrDefault(x => x.IdLink == idLink);
if (link == null)
return new JsonResult(new { successful = false, error = $"Link with ID {idLink} not exists!" });
link.Duration = duration;
context.SaveChanges();
return new JsonResult(new { successful = true, error = $"", link });
}
//Delete
public IActionResult OnDeleteLink(int idLink)
{
var link = context.BulletinBoardPageLinks.FirstOrDefault(x => x.IdLink == idLink);
if (link == null)
return new JsonResult(new { successful = false, error = $"Link with ID {idLink} not exists!", link });
var links = context.BulletinBoardPageLinks
.Where(x => x.IdBulletinBoardFk == link.IdBulletinBoardFk && x.Order > link.Order).ToList();
foreach (var tmpLink in links)
{
tmpLink.Order -= 1;
}
context.BulletinBoardPageLinks.Remove(link);
context.SaveChanges();
return new JsonResult(new { successful = true, error = $"", link });
}
}
}