From dc44390f5bed523430b058ef8e22024587f62b6e Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Fri, 5 Feb 2021 09:23:36 +0330 Subject: [PATCH] #65 fixing GanjoorComment table design fault (InReplyToId) --- ...0210205054558_GanjoorComments.Designer.cs} | 11 ++--- ...s.cs => 20210205054558_GanjoorComments.cs} | 11 ++--- .../RMuseumDbContextModelSnapshot.cs | 9 ++-- RMuseum/Models/Ganjoor/GanjoorComment.cs | 2 +- .../GanjoorCommentSummaryViewModel.cs | 47 +++++++++++++++++++ RMuseum/RMuseum.xml | 40 ++++++++++++++++ .../Services/Implementation/GanjoorService.cs | 43 +++++++++++++++++ .../Models/Auth/ViewModels/LoginViewModel.cs | 2 +- RSecurityBackend/RSecurityBackend.xml | 2 +- 9 files changed, 145 insertions(+), 22 deletions(-) rename RMuseum/Migrations/{20210204114910_GanjoorComments.Designer.cs => 20210205054558_GanjoorComments.Designer.cs} (99%) rename RMuseum/Migrations/{20210204114910_GanjoorComments.cs => 20210205054558_GanjoorComments.cs} (90%) create mode 100644 RMuseum/Models/Ganjoor/ViewModels/GanjoorCommentSummaryViewModel.cs diff --git a/RMuseum/Migrations/20210204114910_GanjoorComments.Designer.cs b/RMuseum/Migrations/20210205054558_GanjoorComments.Designer.cs similarity index 99% rename from RMuseum/Migrations/20210204114910_GanjoorComments.Designer.cs rename to RMuseum/Migrations/20210205054558_GanjoorComments.Designer.cs index eba00f49..af49c1f0 100644 --- a/RMuseum/Migrations/20210204114910_GanjoorComments.Designer.cs +++ b/RMuseum/Migrations/20210205054558_GanjoorComments.Designer.cs @@ -10,7 +10,7 @@ using RMuseum.DbContext; namespace RMuseum.Migrations { [DbContext(typeof(RMuseumDbContext))] - [Migration("20210204114910_GanjoorComments")] + [Migration("20210205054558_GanjoorComments")] partial class GanjoorComments { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -394,10 +394,7 @@ namespace RMuseum.Migrations b.Property("HtmlComment") .HasColumnType("nvarchar(max)"); - b.Property("InReplyToId") - .HasColumnType("uniqueidentifier"); - - b.Property("InReplyToId1") + b.Property("InReplyToId") .HasColumnType("int"); b.Property("PoemId") @@ -411,7 +408,7 @@ namespace RMuseum.Migrations b.HasKey("Id"); - b.HasIndex("InReplyToId1"); + b.HasIndex("InReplyToId"); b.HasIndex("PoemId"); @@ -1847,7 +1844,7 @@ namespace RMuseum.Migrations { b.HasOne("RMuseum.Models.Ganjoor.GanjoorComment", "InReplyTo") .WithMany() - .HasForeignKey("InReplyToId1"); + .HasForeignKey("InReplyToId"); b.HasOne("RMuseum.Models.Ganjoor.GanjoorPoem", "Poem") .WithMany() diff --git a/RMuseum/Migrations/20210204114910_GanjoorComments.cs b/RMuseum/Migrations/20210205054558_GanjoorComments.cs similarity index 90% rename from RMuseum/Migrations/20210204114910_GanjoorComments.cs rename to RMuseum/Migrations/20210205054558_GanjoorComments.cs index bce60507..3694ff42 100644 --- a/RMuseum/Migrations/20210204114910_GanjoorComments.cs +++ b/RMuseum/Migrations/20210205054558_GanjoorComments.cs @@ -21,16 +21,15 @@ namespace RMuseum.Migrations AuthorIpAddress = table.Column(nullable: true), CommentDate = table.Column(nullable: false), HtmlComment = table.Column(nullable: true), - InReplyToId1 = table.Column(nullable: true), - InReplyToId = table.Column(nullable: true), + InReplyToId = table.Column(nullable: true), Status = table.Column(nullable: false) }, constraints: table => { table.PrimaryKey("PK_GanjoorComments", x => x.Id); table.ForeignKey( - name: "FK_GanjoorComments_GanjoorComments_InReplyToId1", - column: x => x.InReplyToId1, + name: "FK_GanjoorComments_GanjoorComments_InReplyToId", + column: x => x.InReplyToId, principalTable: "GanjoorComments", principalColumn: "Id", onDelete: ReferentialAction.Restrict); @@ -49,9 +48,9 @@ namespace RMuseum.Migrations }); migrationBuilder.CreateIndex( - name: "IX_GanjoorComments_InReplyToId1", + name: "IX_GanjoorComments_InReplyToId", table: "GanjoorComments", - column: "InReplyToId1"); + column: "InReplyToId"); migrationBuilder.CreateIndex( name: "IX_GanjoorComments_PoemId", diff --git a/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs b/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs index af1019c3..79678d9c 100644 --- a/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs +++ b/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs @@ -392,10 +392,7 @@ namespace RMuseum.Migrations b.Property("HtmlComment") .HasColumnType("nvarchar(max)"); - b.Property("InReplyToId") - .HasColumnType("uniqueidentifier"); - - b.Property("InReplyToId1") + b.Property("InReplyToId") .HasColumnType("int"); b.Property("PoemId") @@ -409,7 +406,7 @@ namespace RMuseum.Migrations b.HasKey("Id"); - b.HasIndex("InReplyToId1"); + b.HasIndex("InReplyToId"); b.HasIndex("PoemId"); @@ -1845,7 +1842,7 @@ namespace RMuseum.Migrations { b.HasOne("RMuseum.Models.Ganjoor.GanjoorComment", "InReplyTo") .WithMany() - .HasForeignKey("InReplyToId1"); + .HasForeignKey("InReplyToId"); b.HasOne("RMuseum.Models.Ganjoor.GanjoorPoem", "Poem") .WithMany() diff --git a/RMuseum/Models/Ganjoor/GanjoorComment.cs b/RMuseum/Models/Ganjoor/GanjoorComment.cs index 82179b3f..8da22f8b 100644 --- a/RMuseum/Models/Ganjoor/GanjoorComment.cs +++ b/RMuseum/Models/Ganjoor/GanjoorComment.cs @@ -72,7 +72,7 @@ namespace RMuseum.Models.Ganjoor /// /// Reference Comment Id /// - public Guid? InReplyToId { get; set; } + public int? InReplyToId { get; set; } /// /// publish status diff --git a/RMuseum/Models/Ganjoor/ViewModels/GanjoorCommentSummaryViewModel.cs b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCommentSummaryViewModel.cs new file mode 100644 index 00000000..9ba2d14d --- /dev/null +++ b/RMuseum/Models/Ganjoor/ViewModels/GanjoorCommentSummaryViewModel.cs @@ -0,0 +1,47 @@ +using System; + +namespace RMuseum.Models.Ganjoor.ViewModels +{ + /// + /// GanjoorComment Summary View Model + /// + public class GanjoorCommentSummaryViewModel + { + /// + /// Id + /// + public int Id { get; set; } + + /// + /// author name (MySql imported field) + /// + public string AuthorName { get; set; } + + /// + /// author url (MySql imported field) + /// + public string AuthorUrl { get; set; } + + /// + /// comment date + /// + public DateTime CommentDate { get; set; } + + /// + /// comment + /// + public string HtmlComment { get; set; } + + /// + /// status + /// + public string PublishStatus { get; set; } + + /// + /// replies + /// + + public GanjoorCommentSummaryViewModel[] Replies { get; set; } + + } +} diff --git a/RMuseum/RMuseum.xml b/RMuseum/RMuseum.xml index 3b055249..7c5d7bd2 100644 --- a/RMuseum/RMuseum.xml +++ b/RMuseum/RMuseum.xml @@ -4184,6 +4184,46 @@ poems + + + GanjoorComment Summary View Model + + + + + Id + + + + + author name (MySql imported field) + + + + + author url (MySql imported field) + + + + + comment date + + + + + comment + + + + + status + + + + + replies + + Ganjoor Page View Model diff --git a/RMuseum/Services/Implementation/GanjoorService.cs b/RMuseum/Services/Implementation/GanjoorService.cs index 6b805e3b..ab6a64e9 100644 --- a/RMuseum/Services/Implementation/GanjoorService.cs +++ b/RMuseum/Services/Implementation/GanjoorService.cs @@ -15,6 +15,7 @@ using System.Globalization; using System.Linq; using System.Threading.Tasks; using RMuseum.Services.Implementation.ImportedFromDesktopGanjoor; +using RMuseum.Models.Artifact; namespace RMuseum.Services.Implementation { @@ -415,6 +416,48 @@ namespace RMuseum.Services.Implementation return new RServiceResult(null, exp.ToString()); } } + /* + public async Task> GetPoemComments(int id, Guid userId) + { + try + { + var source = + from comment in _context.GanjoorComments + where + (comment.Status == PublishStatus.Published || (userId != Guid.Empty && comment.Status == PublishStatus.Awaiting && comment.UserId == userId)) + && + comment.Id == id + orderby comment.CommentDate + select new GanjoorCommentSummaryViewModel() + { + Id = comment.Id, + }; + return new RServiceResult(await source.ToArrayAsync()); + } + catch (Exception exp) + { + return new RServiceResult(null, exp.ToString()); + } + } + + private async Task _GetPoemComments(int id, Guid userId, int? inReplyToId) + { + var source = + from comment in _context.GanjoorComments + where + (comment.Status == PublishStatus.Published || (userId != Guid.Empty && comment.Status == PublishStatus.Awaiting && comment.UserId == userId)) + && + comment.Id == id + && + comment.InReplyToId == inReplyToId + orderby comment.CommentDate + select new GanjoorCommentSummaryViewModel() + { + Id = comment.Id, + }; + return await source.ToArrayAsync(); + } + */ /// /// get poem images by id (some fields are intentionally field with blank or null), diff --git a/RSecurityBackend/Models/Auth/ViewModels/LoginViewModel.cs b/RSecurityBackend/Models/Auth/ViewModels/LoginViewModel.cs index 6ccff5e4..ae78e173 100644 --- a/RSecurityBackend/Models/Auth/ViewModels/LoginViewModel.cs +++ b/RSecurityBackend/Models/Auth/ViewModels/LoginViewModel.cs @@ -11,7 +11,7 @@ namespace RSecurityBackend.Models.Auth.ViewModels /// username /// /// - /// admin + /// admin@ganjoor.net /// public string Username { get; set; } diff --git a/RSecurityBackend/RSecurityBackend.xml b/RSecurityBackend/RSecurityBackend.xml index 81ae78b3..139983d2 100644 --- a/RSecurityBackend/RSecurityBackend.xml +++ b/RSecurityBackend/RSecurityBackend.xml @@ -1165,7 +1165,7 @@ username - admin + admin@ganjoor.net