diff --git a/ProjectLighthouse.Servers.Website/Pages/AnnouncePage.cshtml b/ProjectLighthouse.Servers.Website/Pages/AnnouncePage.cshtml
index 06710ad2..56e590f1 100644
--- a/ProjectLighthouse.Servers.Website/Pages/AnnouncePage.cshtml
+++ b/ProjectLighthouse.Servers.Website/Pages/AnnouncePage.cshtml
@@ -37,11 +37,21 @@
@foreach (WebsiteAnnouncementEntity announcement in Model.Announcements)
{
-
@announcement.Title
-
- @announcement.Content
-
-
+
+
@announcement.Title
+
+ @announcement.Content
+
+ @if (announcement.Publisher != null)
+ {
+
+ }
+
@if (Model.User != null && Model.User.IsAdmin)
{
}
- }
+ }
}
else
{
diff --git a/ProjectLighthouse.Servers.Website/Pages/AnnouncePage.cshtml.cs b/ProjectLighthouse.Servers.Website/Pages/AnnouncePage.cshtml.cs
index bf4175d4..41b554c6 100644
--- a/ProjectLighthouse.Servers.Website/Pages/AnnouncePage.cshtml.cs
+++ b/ProjectLighthouse.Servers.Website/Pages/AnnouncePage.cshtml.cs
@@ -22,6 +22,7 @@ public class AnnouncePage : BaseLayout
public async Task OnGet()
{
this.Announcements = await this.Database.WebsiteAnnouncements
+ .Include(a => a.Publisher)
.OrderByDescending(a => a.AnnouncementId)
.ToListAsync();
@@ -42,8 +43,9 @@ public class AnnouncePage : BaseLayout
WebsiteAnnouncementEntity announcement = new()
{
- Title = title,
- Content = content,
+ Title = title.Trim(),
+ Content = content.Trim(),
+ PublisherId = user.UserId,
};
await this.Database.WebsiteAnnouncements.AddAsync(announcement);
@@ -55,8 +57,7 @@ public class AnnouncePage : BaseLayout
? content[..250] + $"... [read more]({ServerConfiguration.Instance.ExternalUrl}/announce)"
: content;
- await WebhookHelper.SendWebhook($":mega: {title}",
- truncatedAnnouncement);
+ await WebhookHelper.SendWebhook($":mega: {title}", truncatedAnnouncement);
}
return this.RedirectToPage();
diff --git a/ProjectLighthouse/Migrations/20230624203015_AddPostedByToWebAnnouncements.cs b/ProjectLighthouse/Migrations/20230624203015_AddPostedByToWebAnnouncements.cs
new file mode 100644
index 00000000..830ba80e
--- /dev/null
+++ b/ProjectLighthouse/Migrations/20230624203015_AddPostedByToWebAnnouncements.cs
@@ -0,0 +1,49 @@
+using LBPUnion.ProjectLighthouse.Database;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace ProjectLighthouse.Migrations
+{
+ [DbContext(typeof(DatabaseContext))]
+ [Migration("20230624203015_AddPostedByToWebAnnouncements")]
+ public partial class AddPostedByToWebAnnouncements : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.AddColumn(
+ name: "PublisherId",
+ table: "WebsiteAnnouncements",
+ type: "int",
+ nullable: true);
+
+ migrationBuilder.CreateIndex(
+ name: "IX_WebsiteAnnouncements_PublisherId",
+ table: "WebsiteAnnouncements",
+ column: "PublisherId");
+
+ migrationBuilder.AddForeignKey(
+ name: "FK_WebsiteAnnouncements_Users_PublisherId",
+ table: "WebsiteAnnouncements",
+ column: "PublisherId",
+ principalTable: "Users",
+ principalColumn: "UserId");
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropForeignKey(
+ name: "FK_WebsiteAnnouncements_Users_PublisherId",
+ table: "WebsiteAnnouncements");
+
+ migrationBuilder.DropIndex(
+ name: "IX_WebsiteAnnouncements_PublisherId",
+ table: "WebsiteAnnouncements");
+
+ migrationBuilder.DropColumn(
+ name: "PublisherId",
+ table: "WebsiteAnnouncements");
+ }
+ }
+}
diff --git a/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs b/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs
index 847b390b..2e5991fa 100644
--- a/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs
+++ b/ProjectLighthouse/ProjectLighthouse/Migrations/DatabaseModelSnapshot.cs
@@ -1033,10 +1033,15 @@ namespace ProjectLighthouse.Migrations
b.Property("Content")
.HasColumnType("longtext");
+ b.Property("PublisherId")
+ .HasColumnType("int");
+
b.Property("Title")
.HasColumnType("longtext");
- b.HasKey("Identifier");
+ b.HasKey("AnnouncementId");
+
+ b.HasIndex("PublisherId");
b.ToTable("WebsiteAnnouncements");
});
@@ -1394,6 +1399,15 @@ namespace ProjectLighthouse.Migrations
b.Navigation("User");
});
+ modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Entities.Website.WebsiteAnnouncementEntity", b =>
+ {
+ b.HasOne("LBPUnion.ProjectLighthouse.Types.Entities.Profile.UserEntity", "Publisher")
+ .WithMany()
+ .HasForeignKey("PublisherId");
+
+ b.Navigation("Publisher");
+ });
+
modelBuilder.Entity("LBPUnion.ProjectLighthouse.Types.Entities.Profile.PhotoEntity", b =>
{
b.Navigation("PhotoSubjects");
diff --git a/ProjectLighthouse/Types/Entities/Website/WebsiteAnnouncementEntity.cs b/ProjectLighthouse/Types/Entities/Website/WebsiteAnnouncementEntity.cs
index 26c42488..8749936d 100644
--- a/ProjectLighthouse/Types/Entities/Website/WebsiteAnnouncementEntity.cs
+++ b/ProjectLighthouse/Types/Entities/Website/WebsiteAnnouncementEntity.cs
@@ -1,4 +1,6 @@
using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using LBPUnion.ProjectLighthouse.Types.Entities.Profile;
namespace LBPUnion.ProjectLighthouse.Types.Entities.Website;
@@ -10,4 +12,13 @@ public class WebsiteAnnouncementEntity
public string Title { get; set; }
public string Content { get; set; }
+
+ #nullable enable
+
+ public int? PublisherId { get; set; }
+
+ [ForeignKey(nameof(PublisherId))]
+ public UserEntity? Publisher { get; set; }
+
+ #nullable disable
}
\ No newline at end of file