Skip to content

Commit

Permalink
Merge pull request #89 from SWD392-Domus/feature/quotations-management
Browse files Browse the repository at this point in the history
Feature/quotations management
  • Loading branch information
duykasama authored Mar 3, 2024
2 parents f648506 + 467f7ad commit 951225a
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 205 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
5 changes: 5 additions & 0 deletions Domus.DAL/Domus.DAL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.14" />
</ItemGroup>

<ItemGroup>
<Compile Remove="Interfaces\IProductDetailQuotationRepository.cs" />
<Compile Remove="Implementations\ProductDetailQuotationRepository.cs" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Domus.DAL.Interfaces;
using Domus.Domain.Entities;

namespace Domus.DAL.Implementations;

public class ProductDetailQuoationRevisionRepository : GenericRepository<ProductDetailQuotationRevision>, IProductDetailQuotationRevisionRepository
{
public ProductDetailQuoationRevisionRepository(IAppDbContext dbContext) : base(dbContext)
{
}
}
11 changes: 0 additions & 11 deletions Domus.DAL/Implementations/ProductDetailQuotationRepository.cs

This file was deleted.

11 changes: 11 additions & 0 deletions Domus.DAL/Implementations/QuotationRevisionRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Domus.DAL.Interfaces;
using Domus.Domain.Entities;

namespace Domus.DAL.Implementations;

public class QuotationRevisionRepository : GenericRepository<QuotationRevision>, IQuotationRevisionRepository
{
public QuotationRevisionRepository(IAppDbContext dbContext) : base(dbContext)
{
}
}
8 changes: 0 additions & 8 deletions Domus.DAL/Interfaces/IProductDetailQuotationRepository.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Domus.Common.Interfaces;
using Domus.Domain.Entities;

namespace Domus.DAL.Interfaces;

public interface IProductDetailQuotationRevisionRepository : IGenericRepository<ProductDetailQuotationRevision>, IAutoRegisterable
{
}
8 changes: 8 additions & 0 deletions Domus.DAL/Interfaces/IQuotationRevisionRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Domus.Common.Interfaces;
using Domus.Domain.Entities;

namespace Domus.DAL.Interfaces;

public interface IQuotationRevisionRepository : IGenericRepository<QuotationRevision>, IAutoRegisterable
{
}
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>
18 changes: 18 additions & 0 deletions Domus.Domain/Dtos/Quotations/DtoProductDetailQuotationRevision.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Domus.Domain.Dtos.Products;

namespace Domus.Domain.Dtos.Quotations;

public class DtoProductDetailQuotationRevision
{
public string ProductName { get; set; } = null!;

public double Price { get; set; }

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

public double Quantity { get; set; }

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

public DtoProductDetail Detail { get; set; } = null!;
}
4 changes: 2 additions & 2 deletions Domus.Domain/Dtos/Quotations/DtoQuotationFullDetails.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text.Json.Serialization;
using Domus.Domain.Dtos.Products;

namespace Domus.Domain.Dtos.Quotations;

Expand All @@ -18,7 +17,8 @@ public class DtoQuotationFullDetails
public DateTime? ExpireAt { get; set; }

[JsonPropertyName("products")]
public ICollection<DtoProductDetailQuotation> ProductDetailQuotations { get; set; } = new List<DtoProductDetailQuotation>();
// public ICollection<DtoProductDetailQuotation> ProductDetailQuotations { get; set; } = new List<DtoProductDetailQuotation>();
public ICollection<DtoProductDetailQuotationRevision> ProductDetailQuotations { get; set; } = new List<DtoProductDetailQuotationRevision>();

[JsonPropertyName("services")]
public ICollection<DtoServiceQuotation> ServiceQuotations { get; set; } = new List<DtoServiceQuotation>();
Expand Down
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>();
}
14 changes: 7 additions & 7 deletions Domus.Service/AutoMappings/AutoMapperConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ private static void CreateProductMaps(IMapperConfigurationExpression mapper)
mapper.CreateMap<ProductDetail, DtoProductDetailPackage>()
.ForMember(dest => dest.ProductName, opt => opt.MapFrom(src => src.Product.ProductName));

mapper.CreateMap<ProductDetailQuotation, DtoProductDetailQuotation>()
mapper.CreateMap<ProductDetailQuotationRevision, DtoProductDetailQuotationRevision>()
.ForMember(dest => dest.ProductName,
opt => opt.MapFrom(src => src.ProductDetail.Product.ProductName));

Expand Down Expand Up @@ -196,16 +196,16 @@ private static void CreateQuotationMaps(IMapperConfigurationExpression mapper)
opt => opt.Condition(src => !string.IsNullOrEmpty(src.Status)))
.ForMember(dest => dest.ExpireAt,
opt => opt.Condition(src => src.ExpireAt != default))
.ForMember(dest => dest.ProductDetailQuotations,
.ForMember(dest => dest.QuotationRevisions,
opt => opt.Ignore())
.ForMember(dest => dest.ServiceQuotations,
opt => opt.Ignore());

mapper.CreateMap<ProductDetailInUpdatingQuotationRequest, ProductDetailQuotation>()
.ForMember(dest => dest.MonetaryUnit,
opt => opt.Condition(src => !string.IsNullOrEmpty(src.MonetaryUnit)))
.ForMember(dest => dest.QuantityType,
opt => opt.Condition(src => !string.IsNullOrEmpty(src.QuantityType)));
// mapper.CreateMap<ProductDetailInUpdatingQuotationRequest, ProductDetailQuotation>()
// .ForMember(dest => dest.MonetaryUnit,
// opt => opt.Condition(src => !string.IsNullOrEmpty(src.MonetaryUnit)))
// .ForMember(dest => dest.QuantityType,
// opt => opt.Condition(src => !string.IsNullOrEmpty(src.QuantityType)));

mapper.CreateMap<NegotiationMessage, DtoNegotiationMessage>();
}
Expand Down
Loading

0 comments on commit 951225a

Please sign in to comment.