diff --git a/ProjectLighthouse/Migrations/20220205082513_CommentRefactor.cs b/ProjectLighthouse/Migrations/20220205082513_CommentRefactor.cs deleted file mode 100644 index a42defb2..00000000 --- a/ProjectLighthouse/Migrations/20220205082513_CommentRefactor.cs +++ /dev/null @@ -1,48 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace ProjectLighthouse.Migrations -{ - public partial class CommentRefactor : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Comments_Slots_TargetId", - table: "Comments"); - - migrationBuilder.DropForeignKey( - name: "FK_Comments_Users_TargetId", - table: "Comments"); - - migrationBuilder.DropIndex( - name: "IX_Comments_TargetId", - table: "Comments"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.CreateIndex( - name: "IX_Comments_TargetId", - table: "Comments", - column: "TargetId"); - - migrationBuilder.AddForeignKey( - name: "FK_Comments_Slots_TargetId", - table: "Comments", - column: "TargetId", - principalTable: "Slots", - principalColumn: "SlotId", - onDelete: ReferentialAction.Cascade); - - migrationBuilder.AddForeignKey( - name: "FK_Comments_Users_TargetId", - table: "Comments", - column: "TargetId", - principalTable: "Users", - principalColumn: "UserId", - onDelete: ReferentialAction.Cascade); - } - } -} diff --git a/ProjectLighthouse/Migrations/20220205132152_CommentRefactor.cs b/ProjectLighthouse/Migrations/20220205132152_CommentRefactor.cs new file mode 100644 index 00000000..b03da41d --- /dev/null +++ b/ProjectLighthouse/Migrations/20220205132152_CommentRefactor.cs @@ -0,0 +1,110 @@ +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace ProjectLighthouse.Migrations +{ + public partial class CommentRefactor : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_Comments_Users_TargetUserId", + table: "Comments"); + + migrationBuilder.DropIndex( + name: "IX_Comments_TargetUserId", + table: "Comments"); + + migrationBuilder.RenameColumn( + name: "TargetUserId", + table: "Comments", + newName: "Type"); + + migrationBuilder.AddColumn( + name: "Deleted", + table: "Comments", + type: "tinyint(1)", + nullable: false, + defaultValue: false); + + migrationBuilder.AddColumn( + name: "DeletedBy", + table: "Comments", + type: "longtext", + nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AddColumn( + name: "DeletedType", + table: "Comments", + type: "longtext", + nullable: true) + .Annotation("MySql:CharSet", "utf8mb4"); + + migrationBuilder.AddColumn( + name: "TargetId", + table: "Comments", + type: "int", + nullable: false, + defaultValue: 0); + + migrationBuilder.CreateTable( + name: "Reactions", + columns: table => new + { + RatingId = table.Column(type: "int", nullable: false) + .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn), + UserId = table.Column(type: "int", nullable: false), + TargetId = table.Column(type: "int", nullable: false), + Rating = table.Column(type: "int", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Reactions", x => x.RatingId); + }) + .Annotation("MySql:CharSet", "utf8mb4"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Reactions"); + + migrationBuilder.DropColumn( + name: "Deleted", + table: "Comments"); + + migrationBuilder.DropColumn( + name: "DeletedBy", + table: "Comments"); + + migrationBuilder.DropColumn( + name: "DeletedType", + table: "Comments"); + + migrationBuilder.DropColumn( + name: "TargetId", + table: "Comments"); + + migrationBuilder.RenameColumn( + name: "Type", + table: "Comments", + newName: "TargetUserId"); + + migrationBuilder.CreateIndex( + name: "IX_Comments_TargetUserId", + table: "Comments", + column: "TargetUserId"); + + migrationBuilder.AddForeignKey( + name: "FK_Comments_Users_TargetUserId", + table: "Comments", + column: "TargetUserId", + principalTable: "Users", + principalColumn: "UserId", + onDelete: ReferentialAction.Cascade); + } + } +} diff --git a/ProjectLighthouse/Types/Profiles/Comment.cs b/ProjectLighthouse/Types/Profiles/Comment.cs index 3de7631f..7b296228 100644 --- a/ProjectLighthouse/Types/Profiles/Comment.cs +++ b/ProjectLighthouse/Types/Profiles/Comment.cs @@ -48,15 +48,13 @@ public class Comment { return "This comment has been deleted by the author."; } - else - { - using Database database = new(); - User deletedBy = database.Users.FirstOrDefault(u => u.Username == this.DeletedBy); - if (deletedBy != null && deletedBy.UserId == this.TargetId) - { - return "This comment has been deleted by the player."; - } + using Database database = new(); + User deletedBy = database.Users.FirstOrDefault(u => u.Username == this.DeletedBy); + + if (deletedBy != null && deletedBy.UserId == this.TargetId) + { + return "This comment has been deleted by the player."; } return "This comment has been deleted.";