diff --git a/TASVideos.Data/Entity/User.cs b/TASVideos.Data/Entity/User.cs index 1c9b1cc57..4ac2ef7ae 100644 --- a/TASVideos.Data/Entity/User.cs +++ b/TASVideos.Data/Entity/User.cs @@ -221,4 +221,15 @@ public static IQueryable ThatAreNotBanned(this IQueryable query) => query.Where(u => !u.BannedUntil.HasValue || u.BannedUntil < DateTime.UtcNow); public static bool IsBanned(this User user) => user.BannedUntil.HasValue && user.BannedUntil > DateTime.UtcNow; + + public static IQueryable ToSubmissionAuthors(this IQueryable query, int submissionId, IList authors) + => query + .ForUsers(authors) + .Select(u => new SubmissionAuthor + { + SubmissionId = submissionId, + UserId = u.Id, + Author = u, + Ordinal = authors.IndexOf(u.UserName) + }); } diff --git a/TASVideos/Pages/Submissions/Edit.cshtml.cs b/TASVideos/Pages/Submissions/Edit.cshtml.cs index fc0012d72..0b9c07eeb 100644 --- a/TASVideos/Pages/Submissions/Edit.cshtml.cs +++ b/TASVideos/Pages/Submissions/Edit.cshtml.cs @@ -312,14 +312,7 @@ public async Task OnPost() submission.SubmissionAuthors.Clear(); submission.SubmissionAuthors.AddRange(await db.Users - .ForUsers(Submission.Authors) - .Select(u => new SubmissionAuthor - { - SubmissionId = submission.Id, - UserId = u.Id, - Author = u, - Ordinal = Submission.Authors.IndexOf(u.UserName) - }) + .ToSubmissionAuthors(submission.Id, Submission.Authors) .ToListAsync()); submission.GenerateTitle(); diff --git a/TASVideos/Pages/Submissions/Submit.cshtml.cs b/TASVideos/Pages/Submissions/Submit.cshtml.cs index 190bbaa94..43848737b 100644 --- a/TASVideos/Pages/Submissions/Submit.cshtml.cs +++ b/TASVideos/Pages/Submissions/Submit.cshtml.cs @@ -152,14 +152,7 @@ await wikiPages.Add(new WikiCreateRequest }); db.SubmissionAuthors.AddRange(await db.Users - .ForUsers(Authors) - .Select(u => new SubmissionAuthor - { - SubmissionId = submission.Id, - UserId = u.Id, - Author = u, - Ordinal = Authors.IndexOf(u.UserName) - }) + .ToSubmissionAuthors(submission.Id, Authors) .ToListAsync()); submission.GenerateTitle();