Skip to content

Commit

Permalink
[Quotations management][Duy] Update database
Browse files Browse the repository at this point in the history
- Add QuotationRevision
- Remove ProductDetailQuotation
  • Loading branch information
duykasama committed Mar 3, 2024
1 parent f648506 commit 4fd183d
Show file tree
Hide file tree
Showing 13 changed files with 108 additions and 69 deletions.
2 changes: 2 additions & 0 deletions Domus.Api/Domus.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,7 @@
<EmbeddedResource Include="Scripts\25.Change_Date_To_DateTime.sql" />
<None Remove="Scripts\26.Add_Article_In_Package.sql" />
<EmbeddedResource Include="Scripts\26.Add_Article_In_Package.sql" />
<None Remove="Scripts\27.Add_Table_Quotation_Revision.sql" />
<EmbeddedResource Include="Scripts\27.Add_Table_Quotation_Revision.sql" />
</ItemGroup>
</Project>
23 changes: 23 additions & 0 deletions Domus.Api/Scripts/27.Add_Table_Quotation_Revision.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
DROP TABLE IF EXISTS [ProductDetail_QuotationRevision]
DROP TABLE IF EXISTS [ProductDetail_Quotation]

CREATE TABLE [QuotationRevision] (
[Id] UNIQUEIDENTIFIER NOT NULL PRIMARY KEY,
[QuotationId] UNIQUEIDENTIFIER NOT NULL FOREIGN KEY REFERENCES [Quotation]([Id]),
[Version] INT NOT NULL,
[CreatedAt] DATETIME NOT NULL,
[IsDeleted] BIT NOT NULL
)
GO

CREATE TABLE [ProductDetail_QuotationRevision] (
[Id] UNIQUEIDENTIFIER NOT NULL PRIMARY KEY,
[QuotationRevisionId] UNIQUEIDENTIFIER NOT NULL FOREIGN KEY REFERENCES [QuotationRevision]([Id]),
[ProductDetailId] UNIQUEIDENTIFIER NOT NULL FOREIGN KEY REFERENCES [ProductDetail]([Id]),
[Price] FLOAT NOT NULL,
[MonetaryUnit] NVARCHAR(256) NOT NULL,
[Quantity] FLOAT NOT NULL,
[QuantityType] NVARCHAR(256) NOT NULL,
[IsDeleted] BIT DEFAULT 0
)
GO
11 changes: 0 additions & 11 deletions Domus.DAL/Implementations/ProductDetailQuotationRepository.cs

This file was deleted.

8 changes: 0 additions & 8 deletions Domus.DAL/Interfaces/IProductDetailQuotationRepository.cs

This file was deleted.

32 changes: 16 additions & 16 deletions Domus.Domain/DatabaseMappings/ProductDetailQuotationModelMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ public class ProductDetailQuotationModelMapper : IDatabaseModelMapper
{
public void Map(ModelBuilder modelBuilder)
{
modelBuilder.Entity<ProductDetailQuotation>(entity =>
{
entity.ToTable("ProductDetail_Quotation");
entity.Property(e => e.Id).ValueGeneratedOnAdd();
entity.Property(e => e.MonetaryUnit).HasMaxLength(256);
entity.Property(e => e.QuantityType).HasMaxLength(256);
entity.HasOne(d => d.ProductDetail).WithMany(p => p.ProductDetailQuotations)
.HasForeignKey(d => d.ProductDetailId)
.OnDelete(DeleteBehavior.Cascade);
entity.HasOne(d => d.Quotation).WithMany(p => p.ProductDetailQuotations)
.HasForeignKey(d => d.QuotationId)
.OnDelete(DeleteBehavior.Cascade);
});
// modelBuilder.Entity<ProductDetailQuotation>(entity =>
// {
// entity.ToTable("ProductDetail_Quotation");
//
// entity.Property(e => e.Id).ValueGeneratedOnAdd();
// entity.Property(e => e.MonetaryUnit).HasMaxLength(256);
// entity.Property(e => e.QuantityType).HasMaxLength(256);
//
// entity.HasOne(d => d.ProductDetail).WithMany(p => p.ProductDetailQuotations)
// .HasForeignKey(d => d.ProductDetailId)
// .OnDelete(DeleteBehavior.Cascade);
//
// entity.HasOne(d => d.Quotation).WithMany(p => p.ProductDetailQuotations)
// .HasForeignKey(d => d.QuotationId)
// .OnDelete(DeleteBehavior.Cascade);
// });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,19 @@ public void Map(ModelBuilder modelBuilder)
entity.ToTable("ProductDetail_QuotationRevision");
entity.Property(e => e.Id).ValueGeneratedOnAdd();
entity.Property(e => e.Version).HasDefaultValueSql("((0))");
// entity.Property(e => e.Version).HasDefaultValueSql("((0))");
entity.HasOne(d => d.ProductDetailQuotation).WithMany(p => p.ProductDetailQuotationRevisions)
.HasForeignKey(d => d.ProductDetailQuotationId)
.OnDelete(DeleteBehavior.ClientSetNull);
entity.HasOne(d => d.QuotationRevision).WithMany(p => p.ProductDetailQuotationRevisions)
.HasForeignKey(d => d.QuotationRevisionId)
.OnDelete(DeleteBehavior.ClientSetNull);
entity.HasOne(d => d.ProductDetail).WithMany(p => p.ProductDetailQuotationRevisions)
.HasForeignKey(d => d.ProductDetailId)
.OnDelete(DeleteBehavior.ClientSetNull);
// entity.HasOne(d => d.ProductDetailQuotation).WithMany(p => p.ProductDetailQuotationRevisions)
// .HasForeignKey(d => d.ProductDetailQuotationId)
// .OnDelete(DeleteBehavior.ClientSetNull);
});
}
}
23 changes: 23 additions & 0 deletions Domus.Domain/DatabaseMappings/QuotationRevisionModelMapper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Domus.Domain.Entities;
using Domus.Domain.Interfaces;
using Microsoft.EntityFrameworkCore;

namespace Domus.Domain.DatabaseMappings;

public class QuotationRevisionModelMapper : IDatabaseModelMapper
{
public void Map(ModelBuilder modelBuilder)
{
modelBuilder.Entity<QuotationRevision>(entity =>
{
entity.ToTable("QuotationRevision");
entity.Property(e => e.Id).ValueGeneratedOnAdd();
entity.Property(e => e.CreatedAt).HasColumnType("datetime");
entity.HasOne(d => d.Quotation).WithMany(p => p.QuotationRevisions)
.HasForeignKey(d => d.QuotationId)
.OnDelete(DeleteBehavior.ClientSetNull);
});
}
}
4 changes: 4 additions & 0 deletions Domus.Domain/Domus.Domain.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
</ItemGroup>

<ItemGroup>
<Compile Remove="Entities\ProductDetailQuotation.cs" />
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion Domus.Domain/Entities/ProductDetail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ public partial class ProductDetail : DeletableEntity<Guid>

public virtual ICollection<ProductAttributeValue> ProductAttributeValues { get; set; } = new List<ProductAttributeValue>();

public virtual ICollection<ProductDetailQuotation> ProductDetailQuotations { get; set; } = new List<ProductDetailQuotation>();
// public virtual ICollection<ProductDetailQuotation> ProductDetailQuotations { get; set; } = new List<ProductDetailQuotation>();

public virtual ICollection<ProductDetailQuotationRevision> ProductDetailQuotationRevisions { get; set; } = new List<ProductDetailQuotationRevision>();

public virtual ICollection<ProductImage> ProductImages { get; set; } = new List<ProductImage>();

Expand Down
24 changes: 0 additions & 24 deletions Domus.Domain/Entities/ProductDetailQuotation.cs

This file was deleted.

14 changes: 10 additions & 4 deletions Domus.Domain/Entities/ProductDetailQuotationRevision.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@

namespace Domus.Domain.Entities;

public partial class ProductDetailQuotationRevision : BaseEntity<Guid>
public partial class ProductDetailQuotationRevision : DeletableEntity<Guid>
{
public Guid ProductDetailQuotationId { get; set; }
public Guid QuotationRevisionId { get; set; }

public int? Version { get; set; }
public Guid ProductDetailId { get; set; }

public double Price { get; set; }

public string MonetaryUnit { get; set; } = null!;

public double Quantity { get; set; }

public virtual ProductDetailQuotation ProductDetailQuotation { get; set; } = null!;
public string QuantityType { get; set; } = null!;

public virtual QuotationRevision QuotationRevision { get; set; } = null!;

public virtual ProductDetail ProductDetail { get; set; } = null!;
}
4 changes: 3 additions & 1 deletion Domus.Domain/Entities/Quotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public partial class Quotation : TrackableEntity<Guid, string>

public virtual DomusUser Customer { get; set; } = null!;

public virtual ICollection<ProductDetailQuotation> ProductDetailQuotations { get; set; } = new List<ProductDetailQuotation>();
// public virtual ICollection<ProductDetailQuotation> ProductDetailQuotations { get; set; } = new List<ProductDetailQuotation>();

public virtual ICollection<QuotationRevision> QuotationRevisions { get; set; } = new List<QuotationRevision>();

public virtual ICollection<ServiceQuotation> ServiceQuotations { get; set; } = new List<ServiceQuotation>();

Expand Down
12 changes: 12 additions & 0 deletions Domus.Domain/Entities/QuotationRevision.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Domus.Domain.Entities.Base;

namespace Domus.Domain.Entities;

public partial class QuotationRevision : DeletableEntity<Guid>
{
public Guid QuotationId { get; set; }
public int Version { get; set; }
public DateTime CreatedAt { get; set; }
public virtual Quotation Quotation { get; set; } = null!;
public virtual ICollection<ProductDetailQuotationRevision> ProductDetailQuotationRevisions { get; set; } = new List<ProductDetailQuotationRevision>();
}

0 comments on commit 4fd183d

Please sign in to comment.