feat : add image for product category and brands
parent
b8c6a36e06
commit
72e3e072ff
|
@ -8,7 +8,7 @@ public static class ImageConvertor
|
|||
public static async Task<Stream> ImageResize(this FileUploadRequest fileUpload, Stream input, Stream output, int newWidth)
|
||||
{
|
||||
using var image = await Image.LoadAsync(input);
|
||||
var height_width = image.Height / image.Width;
|
||||
var height_width = image.Width /image.Height;
|
||||
var new_Height = newWidth * height_width;
|
||||
image.Mutate(x => x.Resize(newWidth, new_Height));
|
||||
image.Mutate(x => x.Resize(newWidth, new_Height));
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
using NetinaShop.Domain.Entities.ProductCategories;
|
||||
|
||||
namespace NetinaShop.Domain.Dtos.LargDtos;
|
||||
namespace NetinaShop.Domain.Dtos.LargDtos;
|
||||
|
||||
public class ProductCategoryLDto : BaseDto<ProductCategoryLDto, ProductCategory>
|
||||
{
|
||||
public string Name { get; set; } = string.Empty;
|
||||
public string Description { get; set; } = string.Empty;
|
||||
public Guid ParentId { get; set; }
|
||||
public string ParentName { get; set; } = string.Empty;
|
||||
public bool IsMain { get; set; }
|
||||
public List<ProductCategorySDto> Children { get; set; } = new();
|
||||
public List<StorageFileSDto> Files { get; internal set; } = new();
|
||||
}
|
|
@ -1,6 +1,4 @@
|
|||
using NetinaShop.Domain.Entities.ProductCategories;
|
||||
|
||||
namespace NetinaShop.Domain.Dtos.SmallDtos;
|
||||
namespace NetinaShop.Domain.Dtos.SmallDtos;
|
||||
|
||||
public class ProductCategorySDto : BaseDto<ProductCategorySDto , ProductCategory>
|
||||
{
|
||||
|
@ -9,6 +7,7 @@ public class ProductCategorySDto : BaseDto<ProductCategorySDto , ProductCategory
|
|||
public bool IsMain { get; set; }
|
||||
public Guid ParentId { get; set; }
|
||||
public string ParentName { get; set; } = string.Empty;
|
||||
public string MainImage { get; set; } = string.Empty;
|
||||
|
||||
public List<ProductCategorySDto> Children { get; set; } = new();
|
||||
}
|
|
@ -318,10 +318,10 @@ namespace NetinaShop.Domain.Mappers
|
|||
TaxesPrice = p35.TaxesPrice,
|
||||
TotalPrice = p35.TotalPrice,
|
||||
IsPayed = p35.IsPayed,
|
||||
PayedAt = p35.PayedAt,
|
||||
OrderStatus = p35.OrderStatus,
|
||||
DoneAt = p35.DoneAt,
|
||||
OrderAt = p35.OrderAt,
|
||||
PayedAt = p35.PayedAt,
|
||||
PreparingMinute = p35.PreparingMinute,
|
||||
DiscountCode = p35.DiscountCode,
|
||||
UserId = p35.UserId,
|
||||
|
@ -353,10 +353,10 @@ namespace NetinaShop.Domain.Mappers
|
|||
result.TaxesPrice = p36.TaxesPrice;
|
||||
result.TotalPrice = p36.TotalPrice;
|
||||
result.IsPayed = p36.IsPayed;
|
||||
result.PayedAt = p36.PayedAt;
|
||||
result.OrderStatus = p36.OrderStatus;
|
||||
result.DoneAt = p36.DoneAt;
|
||||
result.OrderAt = p36.OrderAt;
|
||||
result.PayedAt = p36.PayedAt;
|
||||
result.PreparingMinute = p36.PreparingMinute;
|
||||
result.DiscountCode = p36.DiscountCode;
|
||||
result.UserId = p36.UserId;
|
||||
|
|
|
@ -17,7 +17,13 @@ namespace NetinaShop.Domain.Mappers
|
|||
{
|
||||
Name = p1.Name,
|
||||
Description = p1.Description,
|
||||
IsMain = p1.IsMain,
|
||||
ParentId = (Guid?)p1.ParentId,
|
||||
Parent = new ProductCategory()
|
||||
{
|
||||
Name = p1.ParentName,
|
||||
Id = p1.ParentId
|
||||
},
|
||||
Files = funcMain1(p1.Files),
|
||||
Id = p1.Id,
|
||||
CreatedAt = p1.CreatedAt
|
||||
|
@ -33,154 +39,171 @@ namespace NetinaShop.Domain.Mappers
|
|||
|
||||
result.Name = p3.Name;
|
||||
result.Description = p3.Description;
|
||||
result.IsMain = p3.IsMain;
|
||||
result.ParentId = (Guid?)p3.ParentId;
|
||||
result.Files = funcMain2(p3.Files, result.Files);
|
||||
result.Parent = funcMain2(new Never(), result.Parent, p3);
|
||||
result.Files = funcMain3(p3.Files, result.Files);
|
||||
result.Id = p3.Id;
|
||||
result.CreatedAt = p3.CreatedAt;
|
||||
return result;
|
||||
|
||||
}
|
||||
public static Expression<Func<ProductCategoryLDto, ProductCategory>> ProjectToProductCategory => p7 => new ProductCategory()
|
||||
public static Expression<Func<ProductCategoryLDto, ProductCategory>> ProjectToProductCategory => p9 => new ProductCategory()
|
||||
{
|
||||
Name = p7.Name,
|
||||
Description = p7.Description,
|
||||
ParentId = (Guid?)p7.ParentId,
|
||||
Files = p7.Files.Select<StorageFileSDto, ProductCategoryStorageFile>(p8 => new ProductCategoryStorageFile()
|
||||
Name = p9.Name,
|
||||
Description = p9.Description,
|
||||
IsMain = p9.IsMain,
|
||||
ParentId = (Guid?)p9.ParentId,
|
||||
Parent = new ProductCategory()
|
||||
{
|
||||
Name = p8.Name,
|
||||
FileLocation = p8.FileLocation,
|
||||
FileName = p8.FileName,
|
||||
IsHeader = p8.IsHeader,
|
||||
IsPrimary = p8.IsPrimary,
|
||||
FileType = p8.FileType,
|
||||
Id = p8.Id,
|
||||
CreatedAt = p8.CreatedAt
|
||||
Name = p9.ParentName,
|
||||
Id = p9.ParentId
|
||||
},
|
||||
Files = p9.Files.Select<StorageFileSDto, ProductCategoryStorageFile>(p10 => new ProductCategoryStorageFile()
|
||||
{
|
||||
Name = p10.Name,
|
||||
FileLocation = p10.FileLocation,
|
||||
FileName = p10.FileName,
|
||||
IsHeader = p10.IsHeader,
|
||||
IsPrimary = p10.IsPrimary,
|
||||
FileType = p10.FileType,
|
||||
Id = p10.Id,
|
||||
CreatedAt = p10.CreatedAt
|
||||
}).ToList<ProductCategoryStorageFile>(),
|
||||
Id = p7.Id,
|
||||
CreatedAt = p7.CreatedAt
|
||||
Id = p9.Id,
|
||||
CreatedAt = p9.CreatedAt
|
||||
};
|
||||
public static ProductCategoryLDto AdaptToLDto(this ProductCategory p9)
|
||||
public static ProductCategoryLDto AdaptToLDto(this ProductCategory p11)
|
||||
{
|
||||
return p9 == null ? null : new ProductCategoryLDto()
|
||||
return p11 == null ? null : new ProductCategoryLDto()
|
||||
{
|
||||
Name = p9.Name,
|
||||
Description = p9.Description,
|
||||
ParentId = p9.ParentId == null ? default(Guid) : (Guid)p9.ParentId,
|
||||
Files = funcMain3(p9.Files),
|
||||
Id = p9.Id,
|
||||
CreatedAt = p9.CreatedAt
|
||||
Name = p11.Name,
|
||||
Description = p11.Description,
|
||||
ParentId = p11.ParentId == null ? default(Guid) : (Guid)p11.ParentId,
|
||||
ParentName = p11.Parent != null ? p11.Parent.Name : string.Empty,
|
||||
IsMain = p11.IsMain,
|
||||
Files = funcMain4(p11.Files),
|
||||
Id = p11.Id,
|
||||
CreatedAt = p11.CreatedAt
|
||||
};
|
||||
}
|
||||
public static ProductCategoryLDto AdaptTo(this ProductCategory p11, ProductCategoryLDto p12)
|
||||
public static ProductCategoryLDto AdaptTo(this ProductCategory p13, ProductCategoryLDto p14)
|
||||
{
|
||||
if (p11 == null)
|
||||
if (p13 == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ProductCategoryLDto result = p12 ?? new ProductCategoryLDto();
|
||||
ProductCategoryLDto result = p14 ?? new ProductCategoryLDto();
|
||||
|
||||
result.Name = p11.Name;
|
||||
result.Description = p11.Description;
|
||||
result.ParentId = p11.ParentId == null ? default(Guid) : (Guid)p11.ParentId;
|
||||
result.Files = funcMain4(p11.Files, result.Files);
|
||||
result.Id = p11.Id;
|
||||
result.CreatedAt = p11.CreatedAt;
|
||||
result.Name = p13.Name;
|
||||
result.Description = p13.Description;
|
||||
result.ParentId = p13.ParentId == null ? default(Guid) : (Guid)p13.ParentId;
|
||||
result.ParentName = p13.Parent != null ? p13.Parent.Name : string.Empty;
|
||||
result.IsMain = p13.IsMain;
|
||||
result.Files = funcMain5(p13.Files, result.Files);
|
||||
result.Id = p13.Id;
|
||||
result.CreatedAt = p13.CreatedAt;
|
||||
return result;
|
||||
|
||||
}
|
||||
public static Expression<Func<ProductCategory, ProductCategoryLDto>> ProjectToLDto => p15 => new ProductCategoryLDto()
|
||||
public static Expression<Func<ProductCategory, ProductCategoryLDto>> ProjectToLDto => p17 => new ProductCategoryLDto()
|
||||
{
|
||||
Name = p15.Name,
|
||||
Description = p15.Description,
|
||||
ParentId = p15.ParentId == null ? default(Guid) : (Guid)p15.ParentId,
|
||||
Files = p15.Files.Select<ProductCategoryStorageFile, StorageFileSDto>(p16 => new StorageFileSDto()
|
||||
Name = p17.Name,
|
||||
Description = p17.Description,
|
||||
ParentId = p17.ParentId == null ? default(Guid) : (Guid)p17.ParentId,
|
||||
ParentName = p17.Parent != null ? p17.Parent.Name : string.Empty,
|
||||
IsMain = p17.IsMain,
|
||||
Files = p17.Files.Select<ProductCategoryStorageFile, StorageFileSDto>(p18 => new StorageFileSDto()
|
||||
{
|
||||
Name = p16.Name,
|
||||
FileLocation = p16.FileLocation,
|
||||
FileName = p16.FileName,
|
||||
IsHeader = p16.IsHeader,
|
||||
IsPrimary = p16.IsPrimary,
|
||||
FileType = p16.FileType,
|
||||
Id = p16.Id
|
||||
Name = p18.Name,
|
||||
FileLocation = p18.FileLocation,
|
||||
FileName = p18.FileName,
|
||||
IsHeader = p18.IsHeader,
|
||||
IsPrimary = p18.IsPrimary,
|
||||
FileType = p18.FileType,
|
||||
Id = p18.Id
|
||||
}).ToList<StorageFileSDto>(),
|
||||
Id = p15.Id,
|
||||
CreatedAt = p15.CreatedAt
|
||||
Id = p17.Id,
|
||||
CreatedAt = p17.CreatedAt
|
||||
};
|
||||
public static ProductCategory AdaptToProductCategory(this ProductCategorySDto p17)
|
||||
public static ProductCategory AdaptToProductCategory(this ProductCategorySDto p19)
|
||||
{
|
||||
return p17 == null ? null : new ProductCategory()
|
||||
return p19 == null ? null : new ProductCategory()
|
||||
{
|
||||
Name = p17.Name,
|
||||
Description = p17.Description,
|
||||
IsMain = p17.IsMain,
|
||||
ParentId = (Guid?)p17.ParentId,
|
||||
Name = p19.Name,
|
||||
Description = p19.Description,
|
||||
IsMain = p19.IsMain,
|
||||
ParentId = (Guid?)p19.ParentId,
|
||||
Parent = new ProductCategory()
|
||||
{
|
||||
Name = p17.ParentName,
|
||||
Id = p17.ParentId
|
||||
Name = p19.ParentName,
|
||||
Id = p19.ParentId
|
||||
},
|
||||
Id = p17.Id,
|
||||
CreatedAt = p17.CreatedAt
|
||||
Id = p19.Id,
|
||||
CreatedAt = p19.CreatedAt
|
||||
};
|
||||
}
|
||||
public static ProductCategory AdaptTo(this ProductCategorySDto p18, ProductCategory p19)
|
||||
public static ProductCategory AdaptTo(this ProductCategorySDto p20, ProductCategory p21)
|
||||
{
|
||||
if (p18 == null)
|
||||
if (p20 == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ProductCategory result = p19 ?? new ProductCategory();
|
||||
ProductCategory result = p21 ?? new ProductCategory();
|
||||
|
||||
result.Name = p18.Name;
|
||||
result.Description = p18.Description;
|
||||
result.IsMain = p18.IsMain;
|
||||
result.ParentId = (Guid?)p18.ParentId;
|
||||
result.Parent = funcMain5(new Never(), result.Parent, p18);
|
||||
result.Id = p18.Id;
|
||||
result.CreatedAt = p18.CreatedAt;
|
||||
result.Name = p20.Name;
|
||||
result.Description = p20.Description;
|
||||
result.IsMain = p20.IsMain;
|
||||
result.ParentId = (Guid?)p20.ParentId;
|
||||
result.Parent = funcMain6(new Never(), result.Parent, p20);
|
||||
result.Id = p20.Id;
|
||||
result.CreatedAt = p20.CreatedAt;
|
||||
return result;
|
||||
|
||||
}
|
||||
public static ProductCategorySDto AdaptToSDto(this ProductCategory p22)
|
||||
public static ProductCategorySDto AdaptToSDto(this ProductCategory p24)
|
||||
{
|
||||
return p22 == null ? null : new ProductCategorySDto()
|
||||
return p24 == null ? null : new ProductCategorySDto()
|
||||
{
|
||||
Name = p22.Name,
|
||||
Description = p22.Description,
|
||||
IsMain = p22.IsMain,
|
||||
ParentId = p22.ParentId == null ? default(Guid) : (Guid)p22.ParentId,
|
||||
ParentName = p22.Parent != null ? p22.Parent.Name : string.Empty,
|
||||
Id = p22.Id,
|
||||
CreatedAt = p22.CreatedAt
|
||||
Name = p24.Name,
|
||||
Description = p24.Description,
|
||||
IsMain = p24.IsMain,
|
||||
ParentId = p24.ParentId == null ? default(Guid) : (Guid)p24.ParentId,
|
||||
ParentName = p24.Parent != null ? p24.Parent.Name : string.Empty,
|
||||
MainImage = p24.Files.FirstOrDefault<ProductCategoryStorageFile>(funcMain7) != null ? p24.Files.FirstOrDefault<ProductCategoryStorageFile>(funcMain8).FileLocation : (p24.Files.Count > 0 ? p24.Files.FirstOrDefault<ProductCategoryStorageFile>().FileLocation : string.Empty),
|
||||
Id = p24.Id,
|
||||
CreatedAt = p24.CreatedAt
|
||||
};
|
||||
}
|
||||
public static ProductCategorySDto AdaptTo(this ProductCategory p23, ProductCategorySDto p24)
|
||||
public static ProductCategorySDto AdaptTo(this ProductCategory p25, ProductCategorySDto p26)
|
||||
{
|
||||
if (p23 == null)
|
||||
if (p25 == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ProductCategorySDto result = p24 ?? new ProductCategorySDto();
|
||||
ProductCategorySDto result = p26 ?? new ProductCategorySDto();
|
||||
|
||||
result.Name = p23.Name;
|
||||
result.Description = p23.Description;
|
||||
result.IsMain = p23.IsMain;
|
||||
result.ParentId = p23.ParentId == null ? default(Guid) : (Guid)p23.ParentId;
|
||||
result.ParentName = p23.Parent != null ? p23.Parent.Name : string.Empty;
|
||||
result.Id = p23.Id;
|
||||
result.CreatedAt = p23.CreatedAt;
|
||||
result.Name = p25.Name;
|
||||
result.Description = p25.Description;
|
||||
result.IsMain = p25.IsMain;
|
||||
result.ParentId = p25.ParentId == null ? default(Guid) : (Guid)p25.ParentId;
|
||||
result.ParentName = p25.Parent != null ? p25.Parent.Name : string.Empty;
|
||||
result.MainImage = p25.Files.FirstOrDefault<ProductCategoryStorageFile>(funcMain7) != null ? p25.Files.FirstOrDefault<ProductCategoryStorageFile>(funcMain8).FileLocation : (p25.Files.Count > 0 ? p25.Files.FirstOrDefault<ProductCategoryStorageFile>().FileLocation : string.Empty);
|
||||
result.Id = p25.Id;
|
||||
result.CreatedAt = p25.CreatedAt;
|
||||
return result;
|
||||
|
||||
}
|
||||
public static Expression<Func<ProductCategory, ProductCategorySDto>> ProjectToSDto => p25 => new ProductCategorySDto()
|
||||
public static Expression<Func<ProductCategory, ProductCategorySDto>> ProjectToSDto => p27 => new ProductCategorySDto()
|
||||
{
|
||||
Name = p25.Name,
|
||||
Description = p25.Description,
|
||||
IsMain = p25.IsMain,
|
||||
ParentId = p25.ParentId == null ? default(Guid) : (Guid)p25.ParentId,
|
||||
ParentName = p25.Parent != null ? p25.Parent.Name : string.Empty,
|
||||
Id = p25.Id,
|
||||
CreatedAt = p25.CreatedAt
|
||||
Name = p27.Name,
|
||||
Description = p27.Description,
|
||||
IsMain = p27.IsMain,
|
||||
ParentId = p27.ParentId == null ? default(Guid) : (Guid)p27.ParentId,
|
||||
ParentName = p27.Parent != null ? p27.Parent.Name : string.Empty,
|
||||
MainImage = p27.Files.FirstOrDefault<ProductCategoryStorageFile>(f => f.IsPrimary) != null ? p27.Files.FirstOrDefault<ProductCategoryStorageFile>(f => f.IsPrimary).FileLocation : (p27.Files.Count > 0 ? p27.Files.FirstOrDefault<ProductCategoryStorageFile>().FileLocation : string.Empty),
|
||||
Id = p27.Id,
|
||||
CreatedAt = p27.CreatedAt
|
||||
};
|
||||
|
||||
private static List<ProductCategoryStorageFile> funcMain1(List<StorageFileSDto> p2)
|
||||
|
@ -214,20 +237,30 @@ namespace NetinaShop.Domain.Mappers
|
|||
|
||||
}
|
||||
|
||||
private static List<ProductCategoryStorageFile> funcMain2(List<StorageFileSDto> p5, List<ProductCategoryStorageFile> p6)
|
||||
private static ProductCategory funcMain2(Never p5, ProductCategory p6, ProductCategoryLDto p3)
|
||||
{
|
||||
if (p5 == null)
|
||||
ProductCategory result = p6 ?? new ProductCategory();
|
||||
|
||||
result.Name = p3.ParentName;
|
||||
result.Id = p3.ParentId;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private static List<ProductCategoryStorageFile> funcMain3(List<StorageFileSDto> p7, List<ProductCategoryStorageFile> p8)
|
||||
{
|
||||
if (p7 == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<ProductCategoryStorageFile> result = new List<ProductCategoryStorageFile>(p5.Count);
|
||||
List<ProductCategoryStorageFile> result = new List<ProductCategoryStorageFile>(p7.Count);
|
||||
|
||||
int i = 0;
|
||||
int len = p5.Count;
|
||||
int len = p7.Count;
|
||||
|
||||
while (i < len)
|
||||
{
|
||||
StorageFileSDto item = p5[i];
|
||||
StorageFileSDto item = p7[i];
|
||||
result.Add(item == null ? null : new ProductCategoryStorageFile()
|
||||
{
|
||||
Name = item.Name,
|
||||
|
@ -245,20 +278,20 @@ namespace NetinaShop.Domain.Mappers
|
|||
|
||||
}
|
||||
|
||||
private static List<StorageFileSDto> funcMain3(List<ProductCategoryStorageFile> p10)
|
||||
private static List<StorageFileSDto> funcMain4(List<ProductCategoryStorageFile> p12)
|
||||
{
|
||||
if (p10 == null)
|
||||
if (p12 == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<StorageFileSDto> result = new List<StorageFileSDto>(p10.Count);
|
||||
List<StorageFileSDto> result = new List<StorageFileSDto>(p12.Count);
|
||||
|
||||
int i = 0;
|
||||
int len = p10.Count;
|
||||
int len = p12.Count;
|
||||
|
||||
while (i < len)
|
||||
{
|
||||
ProductCategoryStorageFile item = p10[i];
|
||||
ProductCategoryStorageFile item = p12[i];
|
||||
result.Add(item == null ? null : new StorageFileSDto()
|
||||
{
|
||||
Name = item.Name,
|
||||
|
@ -275,20 +308,20 @@ namespace NetinaShop.Domain.Mappers
|
|||
|
||||
}
|
||||
|
||||
private static List<StorageFileSDto> funcMain4(List<ProductCategoryStorageFile> p13, List<StorageFileSDto> p14)
|
||||
private static List<StorageFileSDto> funcMain5(List<ProductCategoryStorageFile> p15, List<StorageFileSDto> p16)
|
||||
{
|
||||
if (p13 == null)
|
||||
if (p15 == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
List<StorageFileSDto> result = new List<StorageFileSDto>(p13.Count);
|
||||
List<StorageFileSDto> result = new List<StorageFileSDto>(p15.Count);
|
||||
|
||||
int i = 0;
|
||||
int len = p13.Count;
|
||||
int len = p15.Count;
|
||||
|
||||
while (i < len)
|
||||
{
|
||||
ProductCategoryStorageFile item = p13[i];
|
||||
ProductCategoryStorageFile item = p15[i];
|
||||
result.Add(item == null ? null : new StorageFileSDto()
|
||||
{
|
||||
Name = item.Name,
|
||||
|
@ -305,14 +338,24 @@ namespace NetinaShop.Domain.Mappers
|
|||
|
||||
}
|
||||
|
||||
private static ProductCategory funcMain5(Never p20, ProductCategory p21, ProductCategorySDto p18)
|
||||
private static ProductCategory funcMain6(Never p22, ProductCategory p23, ProductCategorySDto p20)
|
||||
{
|
||||
ProductCategory result = p21 ?? new ProductCategory();
|
||||
ProductCategory result = p23 ?? new ProductCategory();
|
||||
|
||||
result.Name = p18.ParentName;
|
||||
result.Id = p18.ParentId;
|
||||
result.Name = p20.ParentName;
|
||||
result.Id = p20.ParentId;
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
private static bool funcMain7(ProductCategoryStorageFile f)
|
||||
{
|
||||
return f.IsPrimary;
|
||||
}
|
||||
|
||||
private static bool funcMain8(ProductCategoryStorageFile f)
|
||||
{
|
||||
return f.IsPrimary;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -19,6 +19,11 @@ public class MapsterRegister : IRegister
|
|||
.TwoWays();
|
||||
|
||||
config.NewConfig<ProductCategory, ProductCategorySDto>()
|
||||
.Map("MainImage", o => o.Files.FirstOrDefault(f => f.IsPrimary) != null ? o.Files.FirstOrDefault(f => f.IsPrimary).FileLocation : o.Files.Count > 0 ? o.Files.FirstOrDefault().FileLocation : string.Empty)
|
||||
.Map("ParentName", o => o.Parent != null ? o.Parent.Name : string.Empty)
|
||||
.TwoWays();
|
||||
|
||||
config.NewConfig<ProductCategory, ProductCategoryLDto>()
|
||||
.Map("ParentName", o => o.Parent != null ? o.Parent.Name : string.Empty)
|
||||
.TwoWays();
|
||||
|
||||
|
|
|
@ -21,6 +21,22 @@ public class UpdateBrandCommandHandler : IRequestHandler<UpdateBrandCommand,bool
|
|||
newEnt.Id = ent.Id;
|
||||
newEnt.CreatedAt = ent.CreatedAt;
|
||||
newEnt.CreatedBy = ent.CreatedBy;
|
||||
|
||||
var dbFiles = await _repositoryWrapper.SetRepository<BrandStorageFile>().TableNoTracking
|
||||
.Where(s => s.BrandId == newEnt.Id).ToListAsync(cancellationToken);
|
||||
foreach (var dbFile in dbFiles)
|
||||
{
|
||||
if (request.Files.FirstOrDefault(s => s.Id == dbFile.Id) == null)
|
||||
{
|
||||
_repositoryWrapper.SetRepository<BrandStorageFile>().Delete(dbFile);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
}
|
||||
foreach (var file in request.Files.Where(f => f.Id == default))
|
||||
{
|
||||
newEnt.AddFile(file.Name, file.FileLocation, file.FileName, file.IsHeader, file.IsPrimary, file.FileType);
|
||||
}
|
||||
|
||||
_repositoryWrapper.SetRepository<Brand>().Update(newEnt);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
return true;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using Microsoft.EntityFrameworkCore;
|
||||
using NetinaShop.Domain.Entities.ProductCategories;
|
||||
|
||||
namespace NetinaShop.Repository.Handlers.ProductCategories;
|
||||
|
||||
|
@ -30,7 +29,7 @@ public class UpdateProductCategoryCommandHandler : IRequestHandler<UpdateProduct
|
|||
.Where(s => s.CategoryId == newEnt.Id).ToListAsync(cancellationToken);
|
||||
foreach (var dbFile in dbFiles)
|
||||
{
|
||||
if (request.Files.Any(s => s.Id == dbFile.Id))
|
||||
if (request.Files.FirstOrDefault(s => s.Id == dbFile.Id) == null)
|
||||
{
|
||||
_repositoryWrapper.SetRepository<ProductCategoryStorageFile>().Delete(dbFile);
|
||||
await _repositoryWrapper.SaveChangesAsync(cancellationToken);
|
||||
|
|
Loading…
Reference in New Issue