Skip to content

Commit a4f0daf

Browse files
Merge pull request #46 from DiyorMarket/update-mappings
Update mappings
2 parents 3fe1afc + c1045cd commit a4f0daf

File tree

8 files changed

+24
-17
lines changed

8 files changed

+24
-17
lines changed

Inflow.Domain/DTOs/Product/ProductForUpdateDto.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ public record ProductForUpdateDto(
44
int Id,
55
string Name,
66
string Description,
7-
decimal Price,
7+
decimal SalePrice,
8+
decimal SupplyPrice,
89
DateTime ExpireDate,
910
int CategoryId);
1011
}
+10-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
namespace Inflow.Domain.DTOs.SaleItem
1+
using Inflow.Domain.DTOs.Product;
2+
3+
namespace Inflow.Domain.DTOs.SaleItem
24
{
35
public record SaleItemDto(
4-
int Id,
5-
int Quantity,
6-
decimal UnitPrice,
7-
int ProductId,
8-
int SaleId);
6+
int Id,
7+
string ProductName,
8+
int Quantity,
9+
decimal UnitPrice,
10+
ProductDto Product,
11+
int SaleId,
12+
decimal TotalDue);
913
}

Inflow.Domain/Entities/Category.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
public class Category : EntityBase
44
{
55
public string? Name { get; set; }
6-
public virtual ICollection<Product>? Products { get; set; }
6+
public virtual ICollection<Product> Products { get; set; }
77
}
88
}

Inflow.Domain/Entities/SaleItem.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ public class SaleItem : EntityBase
66
public decimal UnitPrice { get; set; }
77

88
public int ProductId { get; set; }
9-
public Product? Product { get; set; }
9+
public Product Product { get; set; }
1010

1111
public int SaleId { get; set; }
1212
public Sale? Sale { get; set; }

Inflow.Domain/Mappings/CategoryMappings.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace Inflow.Domain.Mappings
66
{
77
public class CategoryMappings : Profile
88
{
9-
public CategoryMappings()
9+
public CategoryMappings()
1010
{
1111
CreateMap<Category, CategoryDto>()
12-
.ForMember(x => x.NumberOfProducts, r => r.MapFrom(x => x.Products.Count));
12+
.ForMember(x => x.NumberOfProducts, r => r.MapFrom(x => x.Products.Count()));
1313
CreateMap<CategoryDto, Category>();
1414
CreateMap<CategoryForCreateDto, Category>();
1515
CreateMap<Category, CategoryForCreateDto>();

Inflow.Domain/Mappings/ProductMappings.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Inflow.Domain.Mappings
66
{
77
public class ProductMappings : Profile
88
{
9-
public ProductMappings()
9+
public ProductMappings()
1010
{
1111
CreateMap<Product, ProductDto>()
1212
.ForMember(x => x.SupplyPrice, r => r.MapFrom(x => x.Price))
@@ -15,7 +15,8 @@ public ProductMappings()
1515
CreateMap<ProductDto, Product>();
1616
CreateMap<ProductForCreateDto, Product>()
1717
.ForMember(x => x.Price, r => r.MapFrom(x => x.SupplyPrice));
18-
CreateMap<ProductForUpdateDto, Product>();
18+
CreateMap<ProductForUpdateDto, Product>()
19+
.ForMember(x => x.Price, r => r.MapFrom(x => x.SupplyPrice));
1920
CreateMap<Product, ProductForCreateDto>();
2021
CreateMap<Product, ProductForUpdateDto>();
2122
}

Inflow.Domain/Mappings/SaleItemMappings.cs

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ namespace Inflow.Domain.Mappings
77
{
88
public class SaleItemMappings : Profile
99
{
10-
public SaleItemMappings()
10+
public SaleItemMappings()
1111
{
1212
CreateMap<SaleItemDto, SaleItem>();
13-
CreateMap<SaleItem, SaleItemDto>();
13+
CreateMap<SaleItem, SaleItemDto>()
14+
.ForCtorParam(nameof(SaleItemDto.TotalDue), x => x.MapFrom(q => q.Quantity * q.UnitPrice))
15+
.ForCtorParam(nameof(SaleItemDto.ProductName), x => x.MapFrom(q => q.Product.Name));
1416
CreateMap<SaleItemForCreateDto, SaleItem>();
1517
CreateMap<SaleItemForUpdateDto, SaleItem>();
1618
}

Inflow.Domain/Mappings/SupplyMappings.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using AutoMapper;
2-
using Inflow.Domain.DTOs.Sale;
32
using Inflow.Domain.DTOs.Supply;
43
using Inflow.Domain.Entities;
54

65
namespace Inflow.Domain.Mappings
76
{
87
public class SupplyMappings : Profile
98
{
10-
public SupplyMappings()
9+
public SupplyMappings()
1110
{
1211
CreateMap<SupplyDto, Supply>()
1312
.PreserveReferences();

0 commit comments

Comments
 (0)