From bd823d2ff253dcb6fcc456bc33dc337887f29fbd Mon Sep 17 00:00:00 2001 From: feos Date: Sat, 20 Jan 2024 18:03:32 +0300 Subject: [PATCH 1/9] edit pub urls without having to delete and readd fix #1113 --- TASVideos.sln | 2 +- TASVideos/Pages/Games/Index.cshtml | 2 +- TASVideos/Pages/Publications/Edit.cshtml | 13 ++- TASVideos/Pages/Publications/EditUrls.cshtml | 62 ----------- TASVideos/Pages/Publications/Urls/Edit.cshtml | 49 +++++++++ .../Edit.cshtml.cs} | 101 +++++++++-------- TASVideos/Pages/Publications/Urls/List.cshtml | 51 +++++++++ .../Pages/Publications/Urls/List.cshtml.cs | 102 ++++++++++++++++++ 8 files changed, 271 insertions(+), 111 deletions(-) delete mode 100644 TASVideos/Pages/Publications/EditUrls.cshtml create mode 100644 TASVideos/Pages/Publications/Urls/Edit.cshtml rename TASVideos/Pages/Publications/{EditUrls.cshtml.cs => Urls/Edit.cshtml.cs} (69%) create mode 100644 TASVideos/Pages/Publications/Urls/List.cshtml create mode 100644 TASVideos/Pages/Publications/Urls/List.cshtml.cs diff --git a/TASVideos.sln b/TASVideos.sln index d14339c8e..51d132eaf 100644 --- a/TASVideos.sln +++ b/TASVideos.sln @@ -52,7 +52,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TASVideos.Api.Tests", "test EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TASVideos.Tests.Base", "tests\TASVideos.Tests.Base\TASVideos.Tests.Base.csproj", "{D4940FE4-3543-4BF1-B3F6-1B959A4DECC2}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TASVideos.ForumEngineTests", "tests\TASVideos.ForumEngineTests\TASVideos.ForumEngineTests.csproj", "{319BC843-E209-4783-A91B-9B3E5A83C661}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TASVideos.ForumEngineTests", "tests\TASVideos.ForumEngineTests\TASVideos.ForumEngineTests.csproj", "{319BC843-E209-4783-A91B-9B3E5A83C661}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/TASVideos/Pages/Games/Index.cshtml b/TASVideos/Pages/Games/Index.cshtml index a18735cf0..65cfc2335 100644 --- a/TASVideos/Pages/Games/Index.cshtml +++ b/TASVideos/Pages/Games/Index.cshtml @@ -167,7 +167,7 @@ No records. - +
diff --git a/TASVideos/Pages/Publications/Edit.cshtml b/TASVideos/Pages/Publications/Edit.cshtml index ea1a0be65..56c6b9417 100644 --- a/TASVideos/Pages/Publications/Edit.cshtml +++ b/TASVideos/Pages/Publications/Edit.cshtml @@ -44,19 +44,22 @@ }
Type Name

- Edit + Edit - - + + @foreach (var url in Model.Publication.Urls.OrderBy(f => f.Type)) { - - + + }
NameUrl TypeUrlName
@url.DisplayName@url.Url @url.Type@url.Url@url.DisplayName
diff --git a/TASVideos/Pages/Publications/EditUrls.cshtml b/TASVideos/Pages/Publications/EditUrls.cshtml deleted file mode 100644 index 3bbdc23c3..000000000 --- a/TASVideos/Pages/Publications/EditUrls.cshtml +++ /dev/null @@ -1,62 +0,0 @@ -@page "{id}/{handler?}/{publicationUrlId?}" -@model EditUrlsModel -@{ - ViewData.SetTitle($"Edit Urls for {Model.Title}"); -} - -

Urls

- - - - - - - - - @foreach (var url in Model.CurrentUrls.OrderBy(u => u.Type)) - { - - - - - - - } -
NameUrlType
@url.DisplayName@url.Url@url.Type - - Delete - -
-
-
-
- - - -
- - - -
-
- - - -
-
- - - -
-
- Add - Back To Edit -
-
-
-
- -@section Scripts { - -} diff --git a/TASVideos/Pages/Publications/Urls/Edit.cshtml b/TASVideos/Pages/Publications/Urls/Edit.cshtml new file mode 100644 index 000000000..48d62c8be --- /dev/null +++ b/TASVideos/Pages/Publications/Urls/Edit.cshtml @@ -0,0 +1,49 @@ +@page "/Publications/{id}/Urls/Edit/{publicationUrlId?}/{handler?}" +@model EditUrlsModel +@{ + string saveBtnName; + string iconClass; + if (Model.publicationUrlId.HasValue) + { + ViewData.SetTitle($"Editing URL #{Model.publicationUrlId} for {Model.Title}"); + saveBtnName = "Save"; + iconClass = "fa fa-save"; + } + else + { + ViewData.SetTitle("Add A New URL"); + saveBtnName = "Add"; + iconClass = "fa fa-plus"; + } +} + +
+ + + +
+ + + +
+
+ + + +
+
+ + + +
+
+ @saveBtnName + Cancel +
+
+
+
+ +@section Scripts { + +} diff --git a/TASVideos/Pages/Publications/EditUrls.cshtml.cs b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs similarity index 69% rename from TASVideos/Pages/Publications/EditUrls.cshtml.cs rename to TASVideos/Pages/Publications/Urls/Edit.cshtml.cs index 33212fcb3..31c01c685 100644 --- a/TASVideos/Pages/Publications/EditUrls.cshtml.cs +++ b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using TASVideos.Core.Services; @@ -7,8 +7,11 @@ using TASVideos.Core.Services.Youtube; using TASVideos.Data; using TASVideos.Data.Entity; +using TASVideos.Data.Entity.Game; +using TASVideos.Pages.Games.Versions.Models; +using static TASVideos.Core.Services.AwardAssignment; -namespace TASVideos.Pages.Publications; +namespace TASVideos.Pages.Publications.Urls; [RequirePermission(PermissionTo.EditPublicationFiles)] public class EditUrlsModel : BasePageModel @@ -49,6 +52,9 @@ public EditUrlsModel( [FromRoute] public int Id { get; set; } + [FromRoute] + public int? publicationUrlId { get; set; } + [BindProperty] public string Title { get; set; } = ""; @@ -62,7 +68,7 @@ public EditUrlsModel( [Required] [BindProperty] [Url] - [Display(Name = "Url")] + [Display(Name = "URL")] public string PublicationUrl { get; set; } = ""; [Required] @@ -87,6 +93,25 @@ public async Task OnGet() .Where(u => u.PublicationId == Id) .ToListAsync(); + if (!publicationUrlId.HasValue) + { + return Page(); + } + + var url = CurrentUrls + .Where(u => u.Id == publicationUrlId.Value) + .SingleOrDefault(); + + if (url is null || url.Url is null) + { + return NotFound(); + } + + Id = url.PublicationId; + DisplayName = url.DisplayName; + UrlType = url.Type; + PublicationUrl = url.Url; + return Page(); } @@ -114,9 +139,9 @@ public async Task OnPost() CurrentUrls = publication.PublicationUrls; - if (CurrentUrls.Any(u => u.Type == UrlType && u.Url == PublicationUrl)) + if (!publicationUrlId.HasValue && CurrentUrls.Any(u => u.Type == UrlType && u.Url == PublicationUrl)) { - ModelState.AddModelError($"{nameof(PublicationUrl)}", $"The {UrlType} url: {PublicationUrl} already exists"); + ModelState.AddModelError($"{nameof(PublicationUrl)}", $"The {UrlType} URL: {PublicationUrl} already exists"); } if (!ModelState.IsValid) @@ -124,25 +149,43 @@ public async Task OnPost() return Page(); } - var publicationUrl = new PublicationUrl + string[] logwording; + + if (publicationUrlId.HasValue) + { + var url = CurrentUrls + .Where(u => u.Id == publicationUrlId.Value) + .Single(); + + url.PublicationId = Id; + url.DisplayName = DisplayName; + url.Type = UrlType; + url.Url = PublicationUrl; + + logwording = new string[2] { "Add", "add" }; + } + else { - PublicationId = Id, - Url = PublicationUrl, - Type = UrlType, - DisplayName = DisplayName - }; + _db.PublicationUrls.Add(new PublicationUrl + { + PublicationId = Id, + Url = PublicationUrl, + Type = UrlType, + DisplayName = DisplayName + }); - _db.PublicationUrls.Add(publicationUrl); + logwording = new string[2] { "Change", "change" }; + } - string log = $"Added {DisplayName} {UrlType} url {PublicationUrl}"; + string log = $"{logwording[0]}ed {DisplayName} {UrlType} url {PublicationUrl}"; await _publicationMaintenanceLogger.Log(Id, User.GetUserId(), log); - var result = await ConcurrentSave(_db, log, "Unable to add url."); + var result = await ConcurrentSave(_db, log, $"Unable to {logwording[1]} URL."); if (result) { await _publisher.SendPublicationEdit( $"{Id}M edited by {User.Name()}", $"[{Id}M]({{0}}) edited by {User.Name()}", - $"Added {UrlType} url | {Title}", + $"{logwording[0]}ed {UrlType} url | {Title}", $"{Id}M"); if (UrlType == PublicationUrlType.Streaming && _youtubeSync.IsYoutubeUrl(PublicationUrl)) @@ -161,32 +204,6 @@ await _publisher.SendPublicationEdit( } } - return RedirectToPage("EditUrls", new { Id }); - } - - public async Task OnPostDelete(int publicationUrlId) - { - var url = await _db.PublicationUrls - .SingleOrDefaultAsync(pf => pf.Id == publicationUrlId); - - if (url != null) - { - _db.PublicationUrls.Remove(url); - string log = $"Deleted {url.DisplayName} {url.Type} url {url.Url}"; - await _publicationMaintenanceLogger.Log(url.PublicationId, User.GetUserId(), log); - var result = await ConcurrentSave(_db, log, "Unable to remove url."); - if (result) - { - await _publisher.SendPublicationEdit( - $"{Id}M edited by {User.Name()}", - $"[{Id}M]({{0}}) edited by {User.Name()}", - $"Deleted {url.Type} url", - $"{Id}M"); - - await _youtubeSync.UnlistVideo(url.Url!); - } - } - - return RedirectToPage("EditUrls", new { Id }); + return RedirectToPage("List", new { Id }); } } diff --git a/TASVideos/Pages/Publications/Urls/List.cshtml b/TASVideos/Pages/Publications/Urls/List.cshtml new file mode 100644 index 000000000..44cff103b --- /dev/null +++ b/TASVideos/Pages/Publications/Urls/List.cshtml @@ -0,0 +1,51 @@ +@page "/Publications/{id}/Urls/List/{publicationUrlId?}/{handler?}" +@model ListUrlsModel +@{ + ViewData.SetTitle($"URLs for {Model.Title}"); +} + +

Movie: @Model.Title

+ Add +
+ + + + + + + + + @foreach (var url in Model.CurrentUrls.OrderBy(u => u.Type)) + { + + + + + + + } +
TypeUrlNameActions
@url.Type@url.Url@url.DisplayName + + Edit + + + Delete + +
+
+ diff --git a/TASVideos/Pages/Publications/Urls/List.cshtml.cs b/TASVideos/Pages/Publications/Urls/List.cshtml.cs new file mode 100644 index 000000000..7dca8ebde --- /dev/null +++ b/TASVideos/Pages/Publications/Urls/List.cshtml.cs @@ -0,0 +1,102 @@ +using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.Rendering; +using TASVideos.Core.Services; +using TASVideos.Core.Services.ExternalMediaPublisher; +using TASVideos.Core.Services.Wiki; +using TASVideos.Core.Services.Youtube; +using TASVideos.Data; +using TASVideos.Data.Entity; + +namespace TASVideos.Pages.Publications.Urls; + +[RequirePermission(PermissionTo.EditPublicationFiles)] +public class ListUrlsModel : BasePageModel +{ + private readonly ApplicationDbContext _db; + private readonly ExternalMediaPublisher _publisher; + private readonly IYoutubeSync _youtubeSync; + private readonly IPublicationMaintenanceLogger _publicationMaintenanceLogger; + + public ListUrlsModel( + ApplicationDbContext db, + ExternalMediaPublisher publisher, + IYoutubeSync youtubeSync, + IPublicationMaintenanceLogger publicationMaintenanceLogger) + { + _db = db; + _publisher = publisher; + _youtubeSync = youtubeSync; + _publicationMaintenanceLogger = publicationMaintenanceLogger; + } + + [FromRoute] + public int Id { get; set; } + + [BindProperty] + public string Title { get; set; } = ""; + + public ICollection CurrentUrls { get; set; } = new List(); + + [StringLength(100)] + [Display(Name = "Alt Title")] + [BindProperty] + public string? DisplayName { get; set; } + + [Required] + [BindProperty] + [Url] + [Display(Name = "Url")] + public string PublicationUrl { get; set; } = ""; + + [Required] + [BindProperty] + [Display(Name = "Type")] + public PublicationUrlType UrlType { get; set; } + + public async Task OnGet() + { + var title = await _db.Publications + .Where(p => p.Id == Id) + .Select(p => p.Title) + .SingleOrDefaultAsync(); + + if (title is null) + { + return NotFound(); + } + + Title = title; + CurrentUrls = await _db.PublicationUrls + .Where(u => u.PublicationId == Id) + .ToListAsync(); + + return Page(); + } + + public async Task OnPostDelete(int publicationUrlId) + { + var url = await _db.PublicationUrls + .SingleOrDefaultAsync(pf => pf.Id == publicationUrlId); + + if (url != null) + { + _db.PublicationUrls.Remove(url); + string log = $"Deleted {url.DisplayName} {url.Type} url {url.Url}"; + await _publicationMaintenanceLogger.Log(url.PublicationId, User.GetUserId(), log); + var result = await ConcurrentSave(_db, log, "Unable to remove url."); + if (result) + { + await _publisher.SendPublicationEdit( + $"{Id}M edited by {User.Name()}", + $"[{Id}M]({{0}}) edited by {User.Name()}", + $"Deleted {url.Type} url", + $"{Id}M"); + + await _youtubeSync.UnlistVideo(url.Url!); + } + } + + return RedirectToPage("List", new { Id }); + } +} From e28ccec9ed6e265e6b8bc23d0b0174228094db34 Mon Sep 17 00:00:00 2001 From: feos Date: Sat, 20 Jan 2024 18:21:48 +0300 Subject: [PATCH 2/9] uppercase URL in UIs --- TASVideos/Pages/Games/Models/GameEditModel.cs | 2 +- TASVideos/Pages/Publications/Edit.cshtml | 2 +- TASVideos/Pages/Publications/EditFiles.cshtml | 2 +- TASVideos/Pages/Publications/Urls/Edit.cshtml.cs | 4 ++-- TASVideos/Pages/Publications/Urls/List.cshtml | 4 ++-- TASVideos/Pages/Publications/Urls/List.cshtml.cs | 8 ++++---- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/TASVideos/Pages/Games/Models/GameEditModel.cs b/TASVideos/Pages/Games/Models/GameEditModel.cs index a86a49d5c..c883de6da 100644 --- a/TASVideos/Pages/Games/Models/GameEditModel.cs +++ b/TASVideos/Pages/Games/Models/GameEditModel.cs @@ -17,7 +17,7 @@ public class GameEditModel public string? Aliases { get; set; } [StringLength(250)] - [Display(Name = "Screenshot Url")] + [Display(Name = "Screenshot URL")] public string? ScreenshotUrl { get; set; } [StringLength(300)] diff --git a/TASVideos/Pages/Publications/Edit.cshtml b/TASVideos/Pages/Publications/Edit.cshtml index 56c6b9417..7da6ef278 100644 --- a/TASVideos/Pages/Publications/Edit.cshtml +++ b/TASVideos/Pages/Publications/Edit.cshtml @@ -51,7 +51,7 @@ - + @foreach (var url in Model.Publication.Urls.OrderBy(f => f.Type)) diff --git a/TASVideos/Pages/Publications/EditFiles.cshtml b/TASVideos/Pages/Publications/EditFiles.cshtml index 92b51a04b..e4b493357 100644 --- a/TASVideos/Pages/Publications/EditFiles.cshtml +++ b/TASVideos/Pages/Publications/EditFiles.cshtml @@ -8,7 +8,7 @@
TypeUrlURL Name
- + diff --git a/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs index 31c01c685..f8720c79c 100644 --- a/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs +++ b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs @@ -177,7 +177,7 @@ public async Task OnPost() logwording = new string[2] { "Change", "change" }; } - string log = $"{logwording[0]}ed {DisplayName} {UrlType} url {PublicationUrl}"; + string log = $"{logwording[0]}ed {DisplayName} {UrlType} URL {PublicationUrl}"; await _publicationMaintenanceLogger.Log(Id, User.GetUserId(), log); var result = await ConcurrentSave(_db, log, $"Unable to {logwording[1]} URL."); if (result) @@ -185,7 +185,7 @@ public async Task OnPost() await _publisher.SendPublicationEdit( $"{Id}M edited by {User.Name()}", $"[{Id}M]({{0}}) edited by {User.Name()}", - $"{logwording[0]}ed {UrlType} url | {Title}", + $"{logwording[0]}ed {UrlType} URL | {Title}", $"{Id}M"); if (UrlType == PublicationUrlType.Streaming && _youtubeSync.IsYoutubeUrl(PublicationUrl)) diff --git a/TASVideos/Pages/Publications/Urls/List.cshtml b/TASVideos/Pages/Publications/Urls/List.cshtml index 44cff103b..50322a12d 100644 --- a/TASVideos/Pages/Publications/Urls/List.cshtml +++ b/TASVideos/Pages/Publications/Urls/List.cshtml @@ -14,7 +14,7 @@
UrlURL Type Description
- + @@ -32,7 +32,7 @@ class="btn btn-primary"> Edit - Delete diff --git a/TASVideos/Pages/Publications/Urls/List.cshtml.cs b/TASVideos/Pages/Publications/Urls/List.cshtml.cs index 7dca8ebde..0cd21da3c 100644 --- a/TASVideos/Pages/Publications/Urls/List.cshtml.cs +++ b/TASVideos/Pages/Publications/Urls/List.cshtml.cs @@ -46,7 +46,7 @@ public ListUrlsModel( [Required] [BindProperty] [Url] - [Display(Name = "Url")] + [Display(Name = "URL")] public string PublicationUrl { get; set; } = ""; [Required] @@ -82,15 +82,15 @@ public async Task OnPostDelete(int publicationUrlId) if (url != null) { _db.PublicationUrls.Remove(url); - string log = $"Deleted {url.DisplayName} {url.Type} url {url.Url}"; + string log = $"Deleted {url.DisplayName} {url.Type} URL {url.Url}"; await _publicationMaintenanceLogger.Log(url.PublicationId, User.GetUserId(), log); - var result = await ConcurrentSave(_db, log, "Unable to remove url."); + var result = await ConcurrentSave(_db, log, "Unable to remove URL."); if (result) { await _publisher.SendPublicationEdit( $"{Id}M edited by {User.Name()}", $"[{Id}M]({{0}}) edited by {User.Name()}", - $"Deleted {url.Type} url", + $"Deleted {url.Type} URL", $"{Id}M"); await _youtubeSync.UnlistVideo(url.Url!); From 12a618c1bfc3d60a9639bdcf7b47674c088c778a Mon Sep 17 00:00:00 2001 From: feos Date: Sat, 20 Jan 2024 19:08:21 +0300 Subject: [PATCH 3/9] renamings --- TASVideos/Pages/Publications/Edit.cshtml | 2 +- TASVideos/Pages/Publications/Urls/Edit.cshtml | 14 ++--- .../Pages/Publications/Urls/Edit.cshtml.cs | 56 +++++++++---------- TASVideos/Pages/Publications/Urls/List.cshtml | 26 +++++---- .../Pages/Publications/Urls/List.cshtml.cs | 18 +++--- 5 files changed, 59 insertions(+), 57 deletions(-) diff --git a/TASVideos/Pages/Publications/Edit.cshtml b/TASVideos/Pages/Publications/Edit.cshtml index 7da6ef278..5362b8a3d 100644 --- a/TASVideos/Pages/Publications/Edit.cshtml +++ b/TASVideos/Pages/Publications/Edit.cshtml @@ -54,7 +54,7 @@ - @foreach (var url in Model.Publication.Urls.OrderBy(f => f.Type)) + @foreach (var url in Model.Publication.Urls.OrderBy(f => f.Type).ThenBy(f => f.DisplayName)) { diff --git a/TASVideos/Pages/Publications/Urls/Edit.cshtml b/TASVideos/Pages/Publications/Urls/Edit.cshtml index 48d62c8be..e8b4c1ec4 100644 --- a/TASVideos/Pages/Publications/Urls/Edit.cshtml +++ b/TASVideos/Pages/Publications/Urls/Edit.cshtml @@ -1,11 +1,11 @@ -@page "/Publications/{id}/Urls/Edit/{publicationUrlId?}/{handler?}" +@page "/Publications/{publicationId}/Urls/Edit/{urlId?}/{handler?}" @model EditUrlsModel @{ string saveBtnName; string iconClass; - if (Model.publicationUrlId.HasValue) + if (Model.UrlId.HasValue) { - ViewData.SetTitle($"Editing URL #{Model.publicationUrlId} for {Model.Title}"); + ViewData.SetTitle($"Editing URL #{Model.UrlId} for {Model.Title}"); saveBtnName = "Save"; iconClass = "fa fa-save"; } @@ -27,9 +27,9 @@
- - - + + +
@@ -38,7 +38,7 @@
@saveBtnName - Cancel + Cancel
diff --git a/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs index f8720c79c..7a4f3c670 100644 --- a/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs +++ b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs @@ -50,10 +50,10 @@ public EditUrlsModel( }); [FromRoute] - public int Id { get; set; } + public int PublicationId { get; set; } [FromRoute] - public int? publicationUrlId { get; set; } + public int? UrlId { get; set; } [BindProperty] public string Title { get; set; } = ""; @@ -69,7 +69,7 @@ public EditUrlsModel( [BindProperty] [Url] [Display(Name = "URL")] - public string PublicationUrl { get; set; } = ""; + public string CurrentUrl { get; set; } = ""; [Required] [BindProperty] @@ -79,7 +79,7 @@ public EditUrlsModel( public async Task OnGet() { var title = await _db.Publications - .Where(p => p.Id == Id) + .Where(p => p.Id == PublicationId) .Select(p => p.Title) .SingleOrDefaultAsync(); @@ -90,16 +90,16 @@ public async Task OnGet() Title = title; CurrentUrls = await _db.PublicationUrls - .Where(u => u.PublicationId == Id) + .Where(u => u.PublicationId == PublicationId) .ToListAsync(); - if (!publicationUrlId.HasValue) + if (!UrlId.HasValue) { return Page(); } var url = CurrentUrls - .Where(u => u.Id == publicationUrlId.Value) + .Where(u => u.Id == UrlId.Value) .SingleOrDefault(); if (url is null || url.Url is null) @@ -107,10 +107,10 @@ public async Task OnGet() return NotFound(); } - Id = url.PublicationId; + PublicationId = url.PublicationId; DisplayName = url.DisplayName; UrlType = url.Type; - PublicationUrl = url.Url; + CurrentUrl = url.Url; return Page(); } @@ -118,7 +118,7 @@ public async Task OnGet() public async Task OnPost() { var publication = await _db.Publications - .Where(p => p.Id == Id) + .Where(p => p.Id == PublicationId) .Select(p => new { Title, @@ -135,13 +135,13 @@ public async Task OnPost() return NotFound(); } - var publicationWiki = await _wikiPages.PublicationPage(Id); + var publicationWiki = await _wikiPages.PublicationPage(PublicationId); CurrentUrls = publication.PublicationUrls; - if (!publicationUrlId.HasValue && CurrentUrls.Any(u => u.Type == UrlType && u.Url == PublicationUrl)) + if (!UrlId.HasValue && CurrentUrls.Any(u => u.Type == UrlType && u.Url == CurrentUrl)) { - ModelState.AddModelError($"{nameof(PublicationUrl)}", $"The {UrlType} URL: {PublicationUrl} already exists"); + ModelState.AddModelError($"{nameof(CurrentUrl)}", $"The {UrlType} URL: {CurrentUrl} already exists"); } if (!ModelState.IsValid) @@ -151,16 +151,16 @@ public async Task OnPost() string[] logwording; - if (publicationUrlId.HasValue) + if (UrlId.HasValue) { var url = CurrentUrls - .Where(u => u.Id == publicationUrlId.Value) + .Where(u => u.Id == UrlId.Value) .Single(); - url.PublicationId = Id; + url.PublicationId = PublicationId; url.DisplayName = DisplayName; url.Type = UrlType; - url.Url = PublicationUrl; + url.Url = CurrentUrl; logwording = new string[2] { "Add", "add" }; } @@ -168,8 +168,8 @@ public async Task OnPost() { _db.PublicationUrls.Add(new PublicationUrl { - PublicationId = Id, - Url = PublicationUrl, + PublicationId = PublicationId, + Url = CurrentUrl, Type = UrlType, DisplayName = DisplayName }); @@ -177,23 +177,23 @@ public async Task OnPost() logwording = new string[2] { "Change", "change" }; } - string log = $"{logwording[0]}ed {DisplayName} {UrlType} URL {PublicationUrl}"; - await _publicationMaintenanceLogger.Log(Id, User.GetUserId(), log); + string log = $"{logwording[0]}ed {DisplayName} {UrlType} URL {CurrentUrl}"; + await _publicationMaintenanceLogger.Log(PublicationId, User.GetUserId(), log); var result = await ConcurrentSave(_db, log, $"Unable to {logwording[1]} URL."); if (result) { await _publisher.SendPublicationEdit( - $"{Id}M edited by {User.Name()}", - $"[{Id}M]({{0}}) edited by {User.Name()}", + $"{PublicationId}M edited by {User.Name()}", + $"[{PublicationId}M]({{0}}) edited by {User.Name()}", $"{logwording[0]}ed {UrlType} URL | {Title}", - $"{Id}M"); + $"{PublicationId}M"); - if (UrlType == PublicationUrlType.Streaming && _youtubeSync.IsYoutubeUrl(PublicationUrl)) + if (UrlType == PublicationUrlType.Streaming && _youtubeSync.IsYoutubeUrl(CurrentUrl)) { YoutubeVideo video = new( - Id, + PublicationId, publication.CreateTimestamp, - PublicationUrl, + CurrentUrl, DisplayName, publication.Title, publicationWiki!, @@ -204,6 +204,6 @@ await _publisher.SendPublicationEdit( } } - return RedirectToPage("List", new { Id }); + return RedirectToPage("List", new { PublicationId }); } } diff --git a/TASVideos/Pages/Publications/Urls/List.cshtml b/TASVideos/Pages/Publications/Urls/List.cshtml index 50322a12d..0a9a475c4 100644 --- a/TASVideos/Pages/Publications/Urls/List.cshtml +++ b/TASVideos/Pages/Publications/Urls/List.cshtml @@ -1,13 +1,13 @@ -@page "/Publications/{id}/Urls/List/{publicationUrlId?}/{handler?}" +@page "/Publications/{publicationId}/Urls/List/{urlId?}/{handler?}" @model ListUrlsModel @{ ViewData.SetTitle($"URLs for {Model.Title}"); } -

Movie: @Model.Title

+

Movie: @Model.Title

Add
@@ -18,23 +18,25 @@
- @foreach (var url in Model.CurrentUrls.OrderBy(u => u.Type)) + @foreach (var url in Model.CurrentUrls.OrderBy(u => u.Type).ThenBy(u => u.DisplayName)) { @@ -44,7 +46,7 @@
Back To Edit diff --git a/TASVideos/Pages/Publications/Urls/List.cshtml.cs b/TASVideos/Pages/Publications/Urls/List.cshtml.cs index 0cd21da3c..74779356d 100644 --- a/TASVideos/Pages/Publications/Urls/List.cshtml.cs +++ b/TASVideos/Pages/Publications/Urls/List.cshtml.cs @@ -31,7 +31,7 @@ public ListUrlsModel( } [FromRoute] - public int Id { get; set; } + public int PublicationId { get; set; } [BindProperty] public string Title { get; set; } = ""; @@ -57,7 +57,7 @@ public ListUrlsModel( public async Task OnGet() { var title = await _db.Publications - .Where(p => p.Id == Id) + .Where(p => p.Id == PublicationId) .Select(p => p.Title) .SingleOrDefaultAsync(); @@ -68,16 +68,16 @@ public async Task OnGet() Title = title; CurrentUrls = await _db.PublicationUrls - .Where(u => u.PublicationId == Id) + .Where(u => u.PublicationId == PublicationId) .ToListAsync(); return Page(); } - public async Task OnPostDelete(int publicationUrlId) + public async Task OnPostDelete(int urlId) { var url = await _db.PublicationUrls - .SingleOrDefaultAsync(pf => pf.Id == publicationUrlId); + .SingleOrDefaultAsync(pf => pf.Id == urlId); if (url != null) { @@ -88,15 +88,15 @@ public async Task OnPostDelete(int publicationUrlId) if (result) { await _publisher.SendPublicationEdit( - $"{Id}M edited by {User.Name()}", - $"[{Id}M]({{0}}) edited by {User.Name()}", + $"{PublicationId}M edited by {User.Name()}", + $"[{PublicationId}M]({{0}}) edited by {User.Name()}", $"Deleted {url.Type} URL", - $"{Id}M"); + $"{PublicationId}M"); await _youtubeSync.UnlistVideo(url.Url!); } } - return RedirectToPage("List", new { Id }); + return RedirectToPage("List", new { PublicationId }); } } From a3132b847bdee11ce5d172debed425605b000d0e Mon Sep 17 00:00:00 2001 From: feos Date: Sat, 20 Jan 2024 19:10:55 +0300 Subject: [PATCH 4/9] revert --- TASVideos.sln | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TASVideos.sln b/TASVideos.sln index 51d132eaf..d14339c8e 100644 --- a/TASVideos.sln +++ b/TASVideos.sln @@ -52,7 +52,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TASVideos.Api.Tests", "test EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TASVideos.Tests.Base", "tests\TASVideos.Tests.Base\TASVideos.Tests.Base.csproj", "{D4940FE4-3543-4BF1-B3F6-1B959A4DECC2}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TASVideos.ForumEngineTests", "tests\TASVideos.ForumEngineTests\TASVideos.ForumEngineTests.csproj", "{319BC843-E209-4783-A91B-9B3E5A83C661}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TASVideos.ForumEngineTests", "tests\TASVideos.ForumEngineTests\TASVideos.ForumEngineTests.csproj", "{319BC843-E209-4783-A91B-9B3E5A83C661}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From d7cd63169065c821d90d5cddaaa3373e929aa8e1 Mon Sep 17 00:00:00 2001 From: feos Date: Sat, 20 Jan 2024 19:42:01 +0300 Subject: [PATCH 5/9] protect against editing an existing url into another existing url --- TASVideos/Pages/Publications/Urls/Edit.cshtml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs index 7a4f3c670..d4a451174 100644 --- a/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs +++ b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs @@ -139,7 +139,7 @@ public async Task OnPost() CurrentUrls = publication.PublicationUrls; - if (!UrlId.HasValue && CurrentUrls.Any(u => u.Type == UrlType && u.Url == CurrentUrl)) + if (CurrentUrls.Any(u => u.Type == UrlType && u.Url == CurrentUrl && u.Id != UrlId)) { ModelState.AddModelError($"{nameof(CurrentUrl)}", $"The {UrlType} URL: {CurrentUrl} already exists"); } From e3f6fa474713bb22053864243f5efc102e56a503 Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 20 Jan 2024 11:02:37 -0600 Subject: [PATCH 6/9] misc cleanups, sorry --- .../Pages/Publications/Urls/Edit.cshtml.cs | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs index d4a451174..cee32dda3 100644 --- a/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs +++ b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs @@ -1,4 +1,4 @@ -using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc.Rendering; using TASVideos.Core.Services; @@ -7,9 +7,6 @@ using TASVideos.Core.Services.Youtube; using TASVideos.Data; using TASVideos.Data.Entity; -using TASVideos.Data.Entity.Game; -using TASVideos.Pages.Games.Versions.Models; -using static TASVideos.Core.Services.AwardAssignment; namespace TASVideos.Pages.Publications.Urls; @@ -99,8 +96,7 @@ public async Task OnGet() } var url = CurrentUrls - .Where(u => u.Id == UrlId.Value) - .SingleOrDefault(); + .SingleOrDefault(u => u.Id == UrlId.Value); if (url is null || url.Url is null) { @@ -149,20 +145,19 @@ public async Task OnPost() return Page(); } - string[] logwording; + string[] logWording; if (UrlId.HasValue) { var url = CurrentUrls - .Where(u => u.Id == UrlId.Value) - .Single(); + .Single(u => u.Id == UrlId.Value); url.PublicationId = PublicationId; url.DisplayName = DisplayName; url.Type = UrlType; url.Url = CurrentUrl; - logwording = new string[2] { "Add", "add" }; + logWording = new[] { "Add", "add" }; } else { @@ -174,18 +169,18 @@ public async Task OnPost() DisplayName = DisplayName }); - logwording = new string[2] { "Change", "change" }; + logWording = new[] { "Change", "change" }; } - string log = $"{logwording[0]}ed {DisplayName} {UrlType} URL {CurrentUrl}"; + string log = $"{logWording[0]}ed {DisplayName} {UrlType} URL {CurrentUrl}"; await _publicationMaintenanceLogger.Log(PublicationId, User.GetUserId(), log); - var result = await ConcurrentSave(_db, log, $"Unable to {logwording[1]} URL."); + var result = await ConcurrentSave(_db, log, $"Unable to {logWording[1]} URL."); if (result) { await _publisher.SendPublicationEdit( $"{PublicationId}M edited by {User.Name()}", $"[{PublicationId}M]({{0}}) edited by {User.Name()}", - $"{logwording[0]}ed {UrlType} URL | {Title}", + $"{logWording[0]}ed {UrlType} URL | {Title}", $"{PublicationId}M"); if (UrlType == PublicationUrlType.Streaming && _youtubeSync.IsYoutubeUrl(CurrentUrl)) From 8f0f2252cdfa65b14e25e34a92def70be295340c Mon Sep 17 00:00:00 2001 From: feos Date: Sat, 20 Jan 2024 20:02:57 +0300 Subject: [PATCH 7/9] fix link --- TASVideos/Pages/Publications/Edit.cshtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TASVideos/Pages/Publications/Edit.cshtml b/TASVideos/Pages/Publications/Edit.cshtml index 5362b8a3d..2360b4de0 100644 --- a/TASVideos/Pages/Publications/Edit.cshtml +++ b/TASVideos/Pages/Publications/Edit.cshtml @@ -46,7 +46,7 @@
Edit
TypeUrlURL Name Actions
URL Name
@url.Type Name Actions
@url.Type @url.Url @url.DisplayName - + asp-route-urlId="@url.Id" + asp-route-publicationId="@Model.PublicationId" + class="btn btn-primary btn-sm mb-1"> Edit - + - Delete + permission="EditPublicationFiles" + asp-href="/Publications/@Model.PublicationId/Urls/List/@url.Id/Delete" + class="btn-sm mb-1"> + Delete
From 934b881ac0d8e7f88b05b810e9c46ee03813e05e Mon Sep 17 00:00:00 2001 From: feos Date: Sat, 20 Jan 2024 20:12:12 +0300 Subject: [PATCH 8/9] fixed log and dropped vars --- TASVideos/Pages/Publications/Urls/Edit.cshtml.cs | 4 ++-- TASVideos/Pages/Publications/Urls/List.cshtml.cs | 16 ---------------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs index cee32dda3..10428054a 100644 --- a/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs +++ b/TASVideos/Pages/Publications/Urls/Edit.cshtml.cs @@ -157,7 +157,7 @@ public async Task OnPost() url.Type = UrlType; url.Url = CurrentUrl; - logWording = new[] { "Add", "add" }; + logWording = new[] { "Chang", "chang" }; } else { @@ -169,7 +169,7 @@ public async Task OnPost() DisplayName = DisplayName }); - logWording = new[] { "Change", "change" }; + logWording = new[] { "Add", "add" }; } string log = $"{logWording[0]}ed {DisplayName} {UrlType} URL {CurrentUrl}"; diff --git a/TASVideos/Pages/Publications/Urls/List.cshtml.cs b/TASVideos/Pages/Publications/Urls/List.cshtml.cs index 74779356d..d7213b259 100644 --- a/TASVideos/Pages/Publications/Urls/List.cshtml.cs +++ b/TASVideos/Pages/Publications/Urls/List.cshtml.cs @@ -38,22 +38,6 @@ public ListUrlsModel( public ICollection CurrentUrls { get; set; } = new List(); - [StringLength(100)] - [Display(Name = "Alt Title")] - [BindProperty] - public string? DisplayName { get; set; } - - [Required] - [BindProperty] - [Url] - [Display(Name = "URL")] - public string PublicationUrl { get; set; } = ""; - - [Required] - [BindProperty] - [Display(Name = "Type")] - public PublicationUrlType UrlType { get; set; } - public async Task OnGet() { var title = await _db.Publications From 96c16d361b65aaa096c30f2023eeb9ed7985235a Mon Sep 17 00:00:00 2001 From: adelikat Date: Sat, 20 Jan 2024 11:39:58 -0600 Subject: [PATCH 9/9] remove [BindProperty] from Title since it is not passed back to the server --- TASVideos/Pages/Publications/Urls/List.cshtml.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/TASVideos/Pages/Publications/Urls/List.cshtml.cs b/TASVideos/Pages/Publications/Urls/List.cshtml.cs index d7213b259..56d128687 100644 --- a/TASVideos/Pages/Publications/Urls/List.cshtml.cs +++ b/TASVideos/Pages/Publications/Urls/List.cshtml.cs @@ -1,9 +1,6 @@ -using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.Rendering; +using Microsoft.AspNetCore.Mvc; using TASVideos.Core.Services; using TASVideos.Core.Services.ExternalMediaPublisher; -using TASVideos.Core.Services.Wiki; using TASVideos.Core.Services.Youtube; using TASVideos.Data; using TASVideos.Data.Entity; @@ -33,7 +30,6 @@ public ListUrlsModel( [FromRoute] public int PublicationId { get; set; } - [BindProperty] public string Title { get; set; } = ""; public ICollection CurrentUrls { get; set; } = new List();