From 827fa3501b0f8242d74dd62da596ce6b48e90a34 Mon Sep 17 00:00:00 2001 From: Hamid Reza Mohammadi Date: Thu, 21 Oct 2021 19:29:53 +0330 Subject: [PATCH] #224 removing redundant data --- GanjooRazor/Areas/Admin/Pages/Poets.cshtml | 5 +++++ ...cs => 20211021153153_GanjoorHalfCenturies.Designer.cs} | 8 +++----- ...enturies.cs => 20211021153153_GanjoorHalfCenturies.cs} | 4 ++-- RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs | 6 ++---- RMuseum/Models/Ganjoor/GanjoorPeriodPoet.cs | 4 ++-- .../GanjoorService-Partials/GanjoorService-Centuries.cs | 4 +++- 6 files changed, 17 insertions(+), 14 deletions(-) rename RMuseum/Migrations/{20211021145514_GanjoorHalfCenturies.Designer.cs => 20211021153153_GanjoorHalfCenturies.Designer.cs} (99%) rename RMuseum/Migrations/{20211021145514_GanjoorHalfCenturies.cs => 20211021153153_GanjoorHalfCenturies.cs} (98%) diff --git a/GanjooRazor/Areas/Admin/Pages/Poets.cshtml b/GanjooRazor/Areas/Admin/Pages/Poets.cshtml index 38a7d6b9..8f424f60 100644 --- a/GanjooRazor/Areas/Admin/Pages/Poets.cshtml +++ b/GanjooRazor/Areas/Admin/Pages/Poets.cshtml @@ -69,6 +69,11 @@ + + + @Html.Raw(poet.Description) + + } diff --git a/RMuseum/Migrations/20211021145514_GanjoorHalfCenturies.Designer.cs b/RMuseum/Migrations/20211021153153_GanjoorHalfCenturies.Designer.cs similarity index 99% rename from RMuseum/Migrations/20211021145514_GanjoorHalfCenturies.Designer.cs rename to RMuseum/Migrations/20211021153153_GanjoorHalfCenturies.Designer.cs index aecb0b3f..da866449 100644 --- a/RMuseum/Migrations/20211021145514_GanjoorHalfCenturies.Designer.cs +++ b/RMuseum/Migrations/20211021153153_GanjoorHalfCenturies.Designer.cs @@ -10,7 +10,7 @@ using RMuseum.DbContext; namespace RMuseum.Migrations { [DbContext(typeof(RMuseumDbContext))] - [Migration("20211021145514_GanjoorHalfCenturies")] + [Migration("20211021153153_GanjoorHalfCenturies")] partial class GanjoorHalfCenturies { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -839,7 +839,7 @@ namespace RMuseum.Migrations b.Property("GanjoorHalfCenturyId") .HasColumnType("int"); - b.Property("PoetId") + b.Property("PoetId") .HasColumnType("int"); b.Property("PoetOrder") @@ -2735,9 +2735,7 @@ namespace RMuseum.Migrations b.HasOne("RMuseum.Models.Ganjoor.GanjoorPoet", "Poet") .WithMany() - .HasForeignKey("PoetId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("PoetId"); b.Navigation("Poet"); }); diff --git a/RMuseum/Migrations/20211021145514_GanjoorHalfCenturies.cs b/RMuseum/Migrations/20211021153153_GanjoorHalfCenturies.cs similarity index 98% rename from RMuseum/Migrations/20211021145514_GanjoorHalfCenturies.cs rename to RMuseum/Migrations/20211021153153_GanjoorHalfCenturies.cs index d01f6086..3b8151fe 100644 --- a/RMuseum/Migrations/20211021145514_GanjoorHalfCenturies.cs +++ b/RMuseum/Migrations/20211021153153_GanjoorHalfCenturies.cs @@ -51,7 +51,7 @@ namespace RMuseum.Migrations Id = table.Column(type: "int", nullable: false) .Annotation("SqlServer:Identity", "1, 1"), PoetOrder = table.Column(type: "int", nullable: false), - PoetId = table.Column(type: "int", nullable: false), + PoetId = table.Column(type: "int", nullable: true), GanjoorHalfCenturyId = table.Column(type: "int", nullable: true) }, constraints: table => @@ -68,7 +68,7 @@ namespace RMuseum.Migrations column: x => x.PoetId, principalTable: "GanjoorPoets", principalColumn: "Id", - onDelete: ReferentialAction.Cascade); + onDelete: ReferentialAction.Restrict); }); migrationBuilder.CreateIndex( diff --git a/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs b/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs index f5449790..3e43cddd 100644 --- a/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs +++ b/RMuseum/Migrations/RMuseumDbContextModelSnapshot.cs @@ -837,7 +837,7 @@ namespace RMuseum.Migrations b.Property("GanjoorHalfCenturyId") .HasColumnType("int"); - b.Property("PoetId") + b.Property("PoetId") .HasColumnType("int"); b.Property("PoetOrder") @@ -2733,9 +2733,7 @@ namespace RMuseum.Migrations b.HasOne("RMuseum.Models.Ganjoor.GanjoorPoet", "Poet") .WithMany() - .HasForeignKey("PoetId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .HasForeignKey("PoetId"); b.Navigation("Poet"); }); diff --git a/RMuseum/Models/Ganjoor/GanjoorPeriodPoet.cs b/RMuseum/Models/Ganjoor/GanjoorPeriodPoet.cs index d9bfb1e1..9b169f65 100644 --- a/RMuseum/Models/Ganjoor/GanjoorPeriodPoet.cs +++ b/RMuseum/Models/Ganjoor/GanjoorPeriodPoet.cs @@ -18,11 +18,11 @@ /// /// poet id /// - public int PoetId { get; set; } + public int? PoetId { get; set; } /// /// poet /// - public GanjoorPoet Poet { get; set; } + public virtual GanjoorPoet Poet { get; set; } } } diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Centuries.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Centuries.cs index ffccb8f1..758a3dc4 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Centuries.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-Centuries.cs @@ -22,9 +22,11 @@ namespace RMuseum.Services.Implementation { try { - var oldOnes = await _context.GanjoorHalfCenturies.Include(o => o.Poets)).ToArrayAsync(); + await _context.Database.ExecuteSqlRawAsync("DELETE FROM GanjoorPeriodPoet"); + var oldOnes = await _context.GanjoorHalfCenturies.ToArrayAsync(); _context.RemoveRange(oldOnes); await _context.SaveChangesAsync(); + var periods = new List {