Fix-variant-display-in-API
This commit is contained in:
@@ -22,6 +22,7 @@ public class ProductService : IProductService
|
||||
.Include(p => p.Category)
|
||||
.Include(p => p.Photos)
|
||||
.Include(p => p.MultiBuys.Where(v => v.IsActive))
|
||||
.Include(p => p.Variants.Where(v => v.IsActive))
|
||||
.Where(p => p.IsActive)
|
||||
.Select(p => new ProductDto
|
||||
{
|
||||
@@ -58,6 +59,19 @@ public class ProductService : IProductService
|
||||
IsActive = mb.IsActive,
|
||||
CreatedAt = mb.CreatedAt,
|
||||
UpdatedAt = mb.UpdatedAt
|
||||
}).ToList(),
|
||||
Variants = p.Variants.Select(v => new ProductVariantDto
|
||||
{
|
||||
Id = v.Id,
|
||||
ProductId = v.ProductId,
|
||||
VariantType = v.VariantType,
|
||||
Name = v.Name,
|
||||
Price = v.Price,
|
||||
StockLevel = v.StockLevel,
|
||||
SortOrder = v.SortOrder,
|
||||
IsActive = v.IsActive,
|
||||
CreatedAt = v.CreatedAt,
|
||||
UpdatedAt = v.UpdatedAt
|
||||
}).ToList()
|
||||
})
|
||||
.ToListAsync();
|
||||
@@ -69,6 +83,7 @@ public class ProductService : IProductService
|
||||
.Include(p => p.Category)
|
||||
.Include(p => p.Photos)
|
||||
.Include(p => p.MultiBuys.Where(v => v.IsActive))
|
||||
.Include(p => p.Variants.Where(v => v.IsActive))
|
||||
.Where(p => p.IsActive && p.CategoryId == categoryId)
|
||||
.Select(p => new ProductDto
|
||||
{
|
||||
@@ -105,6 +120,19 @@ public class ProductService : IProductService
|
||||
IsActive = mb.IsActive,
|
||||
CreatedAt = mb.CreatedAt,
|
||||
UpdatedAt = mb.UpdatedAt
|
||||
}).ToList(),
|
||||
Variants = p.Variants.Select(v => new ProductVariantDto
|
||||
{
|
||||
Id = v.Id,
|
||||
ProductId = v.ProductId,
|
||||
VariantType = v.VariantType,
|
||||
Name = v.Name,
|
||||
Price = v.Price,
|
||||
StockLevel = v.StockLevel,
|
||||
SortOrder = v.SortOrder,
|
||||
IsActive = v.IsActive,
|
||||
CreatedAt = v.CreatedAt,
|
||||
UpdatedAt = v.UpdatedAt
|
||||
}).ToList()
|
||||
})
|
||||
.ToListAsync();
|
||||
@@ -116,6 +144,7 @@ public class ProductService : IProductService
|
||||
.Include(p => p.Category)
|
||||
.Include(p => p.Photos)
|
||||
.Include(p => p.MultiBuys.Where(v => v.IsActive))
|
||||
.Include(p => p.Variants.Where(v => v.IsActive))
|
||||
.FirstOrDefaultAsync(p => p.Id == id);
|
||||
|
||||
if (product == null) return null;
|
||||
@@ -157,6 +186,19 @@ public class ProductService : IProductService
|
||||
IsActive = v.IsActive,
|
||||
CreatedAt = v.CreatedAt,
|
||||
UpdatedAt = v.UpdatedAt
|
||||
}).ToList(),
|
||||
Variants = product.Variants.OrderBy(v => v.SortOrder).Select(v => new ProductVariantDto
|
||||
{
|
||||
Id = v.Id,
|
||||
ProductId = v.ProductId,
|
||||
VariantType = v.VariantType,
|
||||
Name = v.Name,
|
||||
Price = v.Price,
|
||||
StockLevel = v.StockLevel,
|
||||
SortOrder = v.SortOrder,
|
||||
IsActive = v.IsActive,
|
||||
CreatedAt = v.CreatedAt,
|
||||
UpdatedAt = v.UpdatedAt
|
||||
}).ToList()
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user