diff --git a/NetinaShop.Core/Utilities/ImageConvertor.cs b/NetinaShop.Core/Utilities/ImageConvertor.cs index 13914cd..0af3fbb 100644 --- a/NetinaShop.Core/Utilities/ImageConvertor.cs +++ b/NetinaShop.Core/Utilities/ImageConvertor.cs @@ -8,7 +8,7 @@ public static class ImageConvertor public static async Task 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)); diff --git a/NetinaShop.Domain/Dtos/LargDtos/ProductCategoryLDto.cs b/NetinaShop.Domain/Dtos/LargDtos/ProductCategoryLDto.cs index b99e5ce..8c6d9bb 100644 --- a/NetinaShop.Domain/Dtos/LargDtos/ProductCategoryLDto.cs +++ b/NetinaShop.Domain/Dtos/LargDtos/ProductCategoryLDto.cs @@ -1,12 +1,12 @@ -using NetinaShop.Domain.Entities.ProductCategories; - -namespace NetinaShop.Domain.Dtos.LargDtos; +namespace NetinaShop.Domain.Dtos.LargDtos; public class ProductCategoryLDto : BaseDto { 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 Children { get; set; } = new(); public List Files { get; internal set; } = new(); } \ No newline at end of file diff --git a/NetinaShop.Domain/Dtos/SmallDtos/ProductCategorySDto.cs b/NetinaShop.Domain/Dtos/SmallDtos/ProductCategorySDto.cs index 938d68e..710a520 100644 --- a/NetinaShop.Domain/Dtos/SmallDtos/ProductCategorySDto.cs +++ b/NetinaShop.Domain/Dtos/SmallDtos/ProductCategorySDto.cs @@ -1,6 +1,4 @@ -using NetinaShop.Domain.Entities.ProductCategories; - -namespace NetinaShop.Domain.Dtos.SmallDtos; +namespace NetinaShop.Domain.Dtos.SmallDtos; public class ProductCategorySDto : BaseDto { @@ -9,6 +7,7 @@ public class ProductCategorySDto : BaseDto Children { get; set; } = new(); } \ No newline at end of file diff --git a/NetinaShop.Domain/Mappers/OrderMapper.g.cs b/NetinaShop.Domain/Mappers/OrderMapper.g.cs index e5a57b8..6920deb 100644 --- a/NetinaShop.Domain/Mappers/OrderMapper.g.cs +++ b/NetinaShop.Domain/Mappers/OrderMapper.g.cs @@ -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; diff --git a/NetinaShop.Domain/Mappers/ProductCategoryMapper.g.cs b/NetinaShop.Domain/Mappers/ProductCategoryMapper.g.cs index 7394445..243ec56 100644 --- a/NetinaShop.Domain/Mappers/ProductCategoryMapper.g.cs +++ b/NetinaShop.Domain/Mappers/ProductCategoryMapper.g.cs @@ -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> ProjectToProductCategory => p7 => new ProductCategory() + public static Expression> ProjectToProductCategory => p9 => new ProductCategory() { - Name = p7.Name, - Description = p7.Description, - ParentId = (Guid?)p7.ParentId, - Files = p7.Files.Select(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(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(), - 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> ProjectToLDto => p15 => new ProductCategoryLDto() + public static Expression> ProjectToLDto => p17 => new ProductCategoryLDto() { - Name = p15.Name, - Description = p15.Description, - ParentId = p15.ParentId == null ? default(Guid) : (Guid)p15.ParentId, - Files = p15.Files.Select(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(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(), - 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(funcMain7) != null ? p24.Files.FirstOrDefault(funcMain8).FileLocation : (p24.Files.Count > 0 ? p24.Files.FirstOrDefault().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(funcMain7) != null ? p25.Files.FirstOrDefault(funcMain8).FileLocation : (p25.Files.Count > 0 ? p25.Files.FirstOrDefault().FileLocation : string.Empty); + result.Id = p25.Id; + result.CreatedAt = p25.CreatedAt; return result; } - public static Expression> ProjectToSDto => p25 => new ProductCategorySDto() + public static Expression> 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(f => f.IsPrimary) != null ? p27.Files.FirstOrDefault(f => f.IsPrimary).FileLocation : (p27.Files.Count > 0 ? p27.Files.FirstOrDefault().FileLocation : string.Empty), + Id = p27.Id, + CreatedAt = p27.CreatedAt }; private static List funcMain1(List p2) @@ -214,20 +237,30 @@ namespace NetinaShop.Domain.Mappers } - private static List funcMain2(List p5, List 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 funcMain3(List p7, List p8) + { + if (p7 == null) { return null; } - List result = new List(p5.Count); + List result = new List(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 funcMain3(List p10) + private static List funcMain4(List p12) { - if (p10 == null) + if (p12 == null) { return null; } - List result = new List(p10.Count); + List result = new List(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 funcMain4(List p13, List p14) + private static List funcMain5(List p15, List p16) { - if (p13 == null) + if (p15 == null) { return null; } - List result = new List(p13.Count); + List result = new List(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; + } } } \ No newline at end of file diff --git a/NetinaShop.Domain/MapsterRegister.cs b/NetinaShop.Domain/MapsterRegister.cs index 9d86c13..eb3eda4 100644 --- a/NetinaShop.Domain/MapsterRegister.cs +++ b/NetinaShop.Domain/MapsterRegister.cs @@ -19,6 +19,11 @@ public class MapsterRegister : IRegister .TwoWays(); config.NewConfig() + .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() .Map("ParentName", o => o.Parent != null ? o.Parent.Name : string.Empty) .TwoWays(); diff --git a/NetinaShop.Repository/Handlers/Brands/UpdateBrandCommandHandler.cs b/NetinaShop.Repository/Handlers/Brands/UpdateBrandCommandHandler.cs index 7aa23ea..1ed7a05 100644 --- a/NetinaShop.Repository/Handlers/Brands/UpdateBrandCommandHandler.cs +++ b/NetinaShop.Repository/Handlers/Brands/UpdateBrandCommandHandler.cs @@ -21,6 +21,22 @@ public class UpdateBrandCommandHandler : IRequestHandler().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().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().Update(newEnt); await _repositoryWrapper.SaveChangesAsync(cancellationToken); return true; diff --git a/NetinaShop.Repository/Handlers/ProductCategories/UpdateProductCategoryCommandHandler.cs b/NetinaShop.Repository/Handlers/ProductCategories/UpdateProductCategoryCommandHandler.cs index f2c179f..9fa9008 100644 --- a/NetinaShop.Repository/Handlers/ProductCategories/UpdateProductCategoryCommandHandler.cs +++ b/NetinaShop.Repository/Handlers/ProductCategories/UpdateProductCategoryCommandHandler.cs @@ -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 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().Delete(dbFile); await _repositoryWrapper.SaveChangesAsync(cancellationToken);