category
This commit is contained in:
+17
-2
@@ -1,4 +1,5 @@
|
||||
using Vizhvizh.BuildingBlocks.Application.Configuration.Commnad;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Vizhvizh.BuildingBlocks.Application.Configuration.Commnad;
|
||||
using Vizhvizh.GoldGallery.ApplicationContract.Commands;
|
||||
using Vizhvizh.GoldGallery.Domain.Products.Entities;
|
||||
using Vizhvizh.GoldGallery.Domain.Products.Repositories;
|
||||
@@ -10,10 +11,24 @@ public class CreateCategoryCommandHandler(ICategoryRepository categoryRepository
|
||||
{
|
||||
public async Task Handle(CreateCategoryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
CategoryPath? parentPath = null;
|
||||
|
||||
if(request.ParentId != null)
|
||||
{
|
||||
parentPath = await categoryRepository.GetQueryAsNoTracking()
|
||||
.Where(x => x.Id == request.ParentId)
|
||||
.Select(x => x.Path)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
}
|
||||
|
||||
var category = Category.CreateNew(request.Title,
|
||||
request.Description,
|
||||
request.Image, CategoryPath.CreateNew("/1/"));
|
||||
request.Image,
|
||||
request.ParentId);
|
||||
|
||||
await categoryRepository.AddAsync(category, cancellationToken);
|
||||
|
||||
category.SetPath(parentPath);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user