fix : fix update and create product cat , version 0.0.0.8
parent
bbdd8338f4
commit
cfb6238f82
|
@ -43,12 +43,16 @@ public class SeedController : ICarterModule
|
|||
if (key != "kKAYskyG8xPxKnJrHkuYxub4Ao2bnz7AOmNtwDT0RaqzaG7ZvbvaP29tCrC8wJ823RczJFXOIQT2bDOec4F38A==")
|
||||
throw new AppException("Key is not valid", ApiResultStatusCode.UnAuthorized);
|
||||
Dictionary<int,Guid> categories = new Dictionary<int, Guid>();
|
||||
var baseCat = await mediator.Send(new CreateProductCategoryCommand("دسته بندی نشده", "محصولات دسته بندی نشده", default,
|
||||
new List<StorageFileSDto>()));
|
||||
var baseCat = await mediator.Send(new CreateProductCategoryCommand("دسته بندی نشده", "محصولات دسته بندی نشده",
|
||||
true,
|
||||
default,
|
||||
new List<StorageFileSDto>()),cancellationToken);
|
||||
categories.Add(0,baseCat.Id);
|
||||
foreach (var requestDto in request)
|
||||
{
|
||||
var lDto = await mediator.Send(new CreateProductCategoryCommand(requestDto.Name,requestDto.Description,default,new List<StorageFileSDto>()), cancellationToken);
|
||||
var lDto = await mediator.Send(new CreateProductCategoryCommand(requestDto.Name,requestDto.Description,true,default,
|
||||
|
||||
new List<StorageFileSDto>()), cancellationToken);
|
||||
categories.Add(requestDto.BaseCategoryId,lDto.Id);
|
||||
}
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<InvariantGlobalization>true</InvariantGlobalization>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<AssemblyVersion>0.0.0.7</AssemblyVersion>
|
||||
<FileVersion>0.0.0.7</FileVersion>
|
||||
<AssemblyVersion>0.0.0.8</AssemblyVersion>
|
||||
<FileVersion>0.0.0.8</FileVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
public sealed record CreateProductCategoryCommand(
|
||||
string Name,
|
||||
string Description,
|
||||
bool IsMain,
|
||||
Guid ParentId,
|
||||
List<StorageFileSDto> Files) : IRequest<ProductCategoryLDto>;
|
||||
|
||||
|
@ -10,6 +11,7 @@ public sealed record UpdateProductCategoryCommand(
|
|||
Guid Id,
|
||||
string Name,
|
||||
string Description,
|
||||
bool IsMain,
|
||||
Guid ParentId,
|
||||
List<StorageFileSDto> Files) : IRequest<bool>;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ public class ProductCategorySDto : BaseDto<ProductCategorySDto , ProductCategory
|
|||
public string Description { get; set; } = string.Empty;
|
||||
public bool IsMain { get; set; }
|
||||
public Guid ParentId { get; set; }
|
||||
public string ParentName { get; set; } = string.Empty;
|
||||
|
||||
public List<ProductCategorySDto> Children { get; set; } = new();
|
||||
}
|
|
@ -2,9 +2,9 @@
|
|||
|
||||
public partial class ProductCategory
|
||||
{
|
||||
public static ProductCategory Create(string name, string description)
|
||||
public static ProductCategory Create(string name, string description,bool isMain)
|
||||
{
|
||||
return new ProductCategory(name, description);
|
||||
return new ProductCategory(name, description, isMain);
|
||||
}
|
||||
|
||||
public void SetParent(Guid parentId)
|
||||
|
|
|
@ -10,10 +10,11 @@ public partial class ProductCategory : ApiEntity
|
|||
|
||||
}
|
||||
|
||||
public ProductCategory(string name, string description)
|
||||
public ProductCategory(string name, string description,bool isMain)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
IsMain = isMain;
|
||||
}
|
||||
public string Name { get; internal set; } = string.Empty;
|
||||
public string Description { get; internal set; } = string.Empty;
|
||||
|
|
|
@ -8,9 +8,9 @@ using NetinaShop.Domain.Entities.ProductCategories;
|
|||
|
||||
namespace NetinaShop.Domain.Mappers
|
||||
{
|
||||
public static partial class CategoryMapper
|
||||
public static partial class ProductCategoryMapper
|
||||
{
|
||||
public static ProductCategory AdaptToCategory(this ProductCategoryLDto p1)
|
||||
public static ProductCategory AdaptToProductCategory(this ProductCategoryLDto p1)
|
||||
{
|
||||
return p1 == null ? null : new ProductCategory()
|
||||
{
|
||||
|
@ -37,7 +37,7 @@ namespace NetinaShop.Domain.Mappers
|
|||
return result;
|
||||
|
||||
}
|
||||
public static Expression<Func<ProductCategoryLDto, ProductCategory>> ProjectToCategory => p7 => new ProductCategory()
|
||||
public static Expression<Func<ProductCategoryLDto, ProductCategory>> ProjectToProductCategory => p7 => new ProductCategory()
|
||||
{
|
||||
Name = p7.Name,
|
||||
Description = p7.Description,
|
||||
|
@ -98,7 +98,7 @@ namespace NetinaShop.Domain.Mappers
|
|||
}).ToList<StorageFileSDto>(),
|
||||
Id = p15.Id
|
||||
};
|
||||
public static ProductCategory AdaptToCategory(this ProductCategorySDto p17)
|
||||
public static ProductCategory AdaptToProductCategory(this ProductCategorySDto p17)
|
||||
{
|
||||
return p17 == null ? null : new ProductCategory()
|
||||
{
|
||||
|
@ -133,6 +133,7 @@ namespace NetinaShop.Domain.Mappers
|
|||
Description = p20.Description,
|
||||
IsMain = p20.IsMain,
|
||||
ParentId = p20.ParentId == null ? default(Guid) : (Guid)p20.ParentId,
|
||||
ParentName = p20.Parent == null ? null : p20.Parent.Name,
|
||||
Id = p20.Id
|
||||
};
|
||||
}
|
||||
|
@ -148,6 +149,7 @@ namespace NetinaShop.Domain.Mappers
|
|||
result.Description = p21.Description;
|
||||
result.IsMain = p21.IsMain;
|
||||
result.ParentId = p21.ParentId == null ? default(Guid) : (Guid)p21.ParentId;
|
||||
result.ParentName = p21.Parent == null ? null : p21.Parent.Name;
|
||||
result.Id = p21.Id;
|
||||
return result;
|
||||
|
||||
|
@ -158,6 +160,7 @@ namespace NetinaShop.Domain.Mappers
|
|||
Description = p23.Description,
|
||||
IsMain = p23.IsMain,
|
||||
ParentId = p23.ParentId == null ? default(Guid) : (Guid)p23.ParentId,
|
||||
ParentName = p23.Parent.Name,
|
||||
Id = p23.Id
|
||||
};
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
namespace NetinaShop.Domain.Mappers
|
||||
{
|
||||
public static partial class ProductCategoryStorageFileMapper
|
||||
{
|
||||
}
|
||||
}
|
|
@ -238,6 +238,7 @@ namespace NetinaShop.Domain.Mappers
|
|||
Viewed = p36.Viewed,
|
||||
CategoryId = p36.CategoryId,
|
||||
BrandId = p36.BrandId,
|
||||
CategoryName = p36.Category == null ? null : p36.Category.Name,
|
||||
Id = p36.Id
|
||||
};
|
||||
}
|
||||
|
@ -264,6 +265,7 @@ namespace NetinaShop.Domain.Mappers
|
|||
result.Viewed = p37.Viewed;
|
||||
result.CategoryId = p37.CategoryId;
|
||||
result.BrandId = p37.BrandId;
|
||||
result.CategoryName = p37.Category == null ? null : p37.Category.Name;
|
||||
result.Id = p37.Id;
|
||||
return result;
|
||||
|
||||
|
@ -285,6 +287,7 @@ namespace NetinaShop.Domain.Mappers
|
|||
Viewed = p39.Viewed,
|
||||
CategoryId = p39.CategoryId,
|
||||
BrandId = p39.BrandId,
|
||||
CategoryName = p39.Category.Name,
|
||||
Id = p39.Id
|
||||
};
|
||||
|
||||
|
|
|
@ -11,5 +11,9 @@ public class MapsterRegister : IRegister
|
|||
config.NewConfig<Brand, BrandSDto>()
|
||||
.Map("HeaderFileName", o => o.Files.Count > 0 && o.Files.Any(f => f.IsHeader) ? o.Files.FirstOrDefault(f => f.IsHeader)!.FileName : string.Empty)
|
||||
.TwoWays();
|
||||
|
||||
config.NewConfig<ProductCategory, ProductSDto>()
|
||||
.Map("ParentName", o => o.Parent != null ? o.Parent.Name : string.Empty)
|
||||
.TwoWays();
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ public class CreateProductCategoryCommandHandler : IRequestHandler<CreateProduct
|
|||
}
|
||||
public async Task<ProductCategoryLDto> Handle(CreateProductCategoryCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var ent = ProductCategory.Create(request.Name, request.Description);
|
||||
var ent = ProductCategory.Create(request.Name, request.Description, request.IsMain);
|
||||
if (request.ParentId != default)
|
||||
ent.SetParent(request.ParentId);
|
||||
foreach (var file in request.Files)
|
||||
|
|
|
@ -32,13 +32,13 @@ public class GetProductCategoriesQueryHandler : IRequestHandler<GetProductCatego
|
|||
{
|
||||
groupCats = await basCategories
|
||||
.Skip(request.Page.Value * 15).Take(15)
|
||||
.Select(CategoryMapper.ProjectToSDto)
|
||||
.Select(ProductCategoryMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
else
|
||||
{
|
||||
groupCats = await basCategories
|
||||
.Select(CategoryMapper.ProjectToSDto)
|
||||
.Select(ProductCategoryMapper.ProjectToSDto)
|
||||
.ToListAsync(cancellationToken);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ public class GetProductCategoryQueryHandler : IRequestHandler<GetProductCategory
|
|||
{
|
||||
var ent = await _repositoryWrapper.SetRepository<ProductCategory>().TableNoTracking
|
||||
.Where(b => b.Id == request.Id)
|
||||
.Select(CategoryMapper.ProjectToLDto)
|
||||
.Select(ProductCategoryMapper.ProjectToLDto)
|
||||
.FirstOrDefaultAsync(cancellationToken);
|
||||
if (ent == null)
|
||||
throw new AppException("ProductCategory not found", ApiResultStatusCode.NotFound);
|
||||
|
|
|
@ -17,7 +17,7 @@ public class UpdateProductCategoryCommandHandler : IRequestHandler<UpdateProduct
|
|||
if (ent == null)
|
||||
throw new AppException("ProductCategory not found", ApiResultStatusCode.NotFound);
|
||||
|
||||
var newEnt = ProductCategory.Create(request.Name, request.Description);
|
||||
var newEnt = ProductCategory.Create(request.Name, request.Description, request.IsMain);
|
||||
newEnt.Id = ent.Id;
|
||||
if (request.ParentId != default)
|
||||
newEnt.SetParent(request.ParentId);
|
||||
|
|
Loading…
Reference in New Issue