using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using Mapster.Models; using NetinaShop.Domain.Dtos.LargDtos; using NetinaShop.Domain.Dtos.SmallDtos; using NetinaShop.Domain.Entities.Brands; using NetinaShop.Domain.Entities.ProductCategories; using NetinaShop.Domain.Entities.Products; namespace NetinaShop.Domain.Mappers { public static partial class ProductMapper { public static Product AdaptToProduct(this ProductLDto p1) { return p1 == null ? null : new Product() { PersianName = p1.PersianName, EnglishName = p1.EnglishName, Summery = p1.Summery, ExpertCheck = p1.ExpertCheck, Tags = p1.Tags, Warranty = p1.Warranty, Cost = p1.Cost, BeDisplayed = p1.BeDisplayed, PackingCost = p1.PackingCost, Stock = p1.Stock, HasExpressDelivery = p1.HasExpressDelivery, MaxOrderCount = p1.MaxOrderCount, BrandId = p1.BrandId, Brand = new Brand() {Id = p1.BrandId}, CategoryId = p1.CategoryId, Category = new ProductCategory() { Name = p1.CategoryName, Id = p1.CategoryId }, Specifications = funcMain1(p1.Specifications), Reviews = funcMain2(p1.Reviews), Files = funcMain3(p1.Files), Id = p1.Id, CreatedAt = p1.CreatedAt }; } public static Product AdaptTo(this ProductLDto p5, Product p6) { if (p5 == null) { return null; } Product result = p6 ?? new Product(); result.PersianName = p5.PersianName; result.EnglishName = p5.EnglishName; result.Summery = p5.Summery; result.ExpertCheck = p5.ExpertCheck; result.Tags = p5.Tags; result.Warranty = p5.Warranty; result.Cost = p5.Cost; result.BeDisplayed = p5.BeDisplayed; result.PackingCost = p5.PackingCost; result.Stock = p5.Stock; result.HasExpressDelivery = p5.HasExpressDelivery; result.MaxOrderCount = p5.MaxOrderCount; result.BrandId = p5.BrandId; result.Brand = funcMain4(new Never(), result.Brand, p5); result.CategoryId = p5.CategoryId; result.Category = funcMain5(new Never(), result.Category, p5); result.Specifications = funcMain6(p5.Specifications, result.Specifications); result.Reviews = funcMain7(p5.Reviews, result.Reviews); result.Files = funcMain8(p5.Files, result.Files); result.Id = p5.Id; result.CreatedAt = p5.CreatedAt; return result; } public static Expression> ProjectToProduct => p17 => new Product() { PersianName = p17.PersianName, EnglishName = p17.EnglishName, Summery = p17.Summery, ExpertCheck = p17.ExpertCheck, Tags = p17.Tags, Warranty = p17.Warranty, Cost = p17.Cost, BeDisplayed = p17.BeDisplayed, PackingCost = p17.PackingCost, Stock = p17.Stock, HasExpressDelivery = p17.HasExpressDelivery, MaxOrderCount = p17.MaxOrderCount, BrandId = p17.BrandId, Brand = new Brand() {Id = p17.BrandId}, CategoryId = p17.CategoryId, Category = new ProductCategory() { Name = p17.CategoryName, Id = p17.CategoryId }, Specifications = p17.Specifications.Select(p18 => new Specification() { Title = p18.Title, Detail = p18.Detail, Value = p18.Value, IsFeature = p18.IsFeature, ProductId = p18.ProductId, ParentId = (Guid?)p18.ParentId, Id = p18.Id, CreatedAt = p18.CreatedAt }).ToList(), Reviews = p17.Reviews.Select(p19 => new Review() { Title = p19.Title, Comment = p19.Comment, Rate = p19.Rate, IsBuyer = p19.IsBuyer, ProductId = p19.ProductId, UserId = p19.UserId, Id = p19.Id, CreatedAt = p19.CreatedAt }).ToList(), Files = p17.Files.Select(p20 => new ProductStorageFile() { Name = p20.Name, FileLocation = p20.FileLocation, FileName = p20.FileName, IsHeader = p20.IsHeader, IsPrimary = p20.IsPrimary, FileType = p20.FileType, Id = p20.Id, CreatedAt = p20.CreatedAt }).ToList(), Id = p17.Id, CreatedAt = p17.CreatedAt }; public static ProductLDto AdaptToLDto(this Product p21) { return p21 == null ? null : new ProductLDto() { PersianName = p21.PersianName, EnglishName = p21.EnglishName, Summery = p21.Summery, ExpertCheck = p21.ExpertCheck, Tags = p21.Tags, Warranty = p21.Warranty, BeDisplayed = p21.BeDisplayed, HasExpressDelivery = p21.HasExpressDelivery, Cost = p21.Cost, PackingCost = p21.PackingCost, MaxOrderCount = p21.MaxOrderCount, Stock = p21.Stock, BrandId = p21.BrandId, BrandName = p21.Brand == null ? null : p21.Brand.PersianName, CategoryId = p21.CategoryId, CategoryName = p21.Category == null ? null : p21.Category.Name, Specifications = funcMain9(p21.Specifications), Reviews = funcMain10(p21.Reviews), Files = funcMain11(p21.Files), Id = p21.Id, CreatedAt = p21.CreatedAt }; } public static ProductLDto AdaptTo(this Product p25, ProductLDto p26) { if (p25 == null) { return null; } ProductLDto result = p26 ?? new ProductLDto(); result.PersianName = p25.PersianName; result.EnglishName = p25.EnglishName; result.Summery = p25.Summery; result.ExpertCheck = p25.ExpertCheck; result.Tags = p25.Tags; result.Warranty = p25.Warranty; result.BeDisplayed = p25.BeDisplayed; result.HasExpressDelivery = p25.HasExpressDelivery; result.Cost = p25.Cost; result.PackingCost = p25.PackingCost; result.MaxOrderCount = p25.MaxOrderCount; result.Stock = p25.Stock; result.BrandId = p25.BrandId; result.BrandName = p25.Brand == null ? null : p25.Brand.PersianName; result.CategoryId = p25.CategoryId; result.CategoryName = p25.Category == null ? null : p25.Category.Name; result.Specifications = funcMain12(p25.Specifications, result.Specifications); result.Reviews = funcMain13(p25.Reviews, result.Reviews); result.Files = funcMain14(p25.Files, result.Files); result.Id = p25.Id; result.CreatedAt = p25.CreatedAt; return result; } public static Expression> ProjectToLDto => p33 => new ProductLDto() { PersianName = p33.PersianName, EnglishName = p33.EnglishName, Summery = p33.Summery, ExpertCheck = p33.ExpertCheck, Tags = p33.Tags, Warranty = p33.Warranty, BeDisplayed = p33.BeDisplayed, HasExpressDelivery = p33.HasExpressDelivery, Cost = p33.Cost, PackingCost = p33.PackingCost, MaxOrderCount = p33.MaxOrderCount, Stock = p33.Stock, BrandId = p33.BrandId, BrandName = p33.Brand == null ? null : p33.Brand.PersianName, CategoryId = p33.CategoryId, CategoryName = p33.Category == null ? null : p33.Category.Name, Specifications = p33.Specifications.Select(p34 => new SpecificationSDto() { Title = p34.Title, Detail = p34.Detail, Value = p34.Value, IsFeature = p34.IsFeature, ProductId = p34.ProductId, ParentId = p34.ParentId == null ? default(Guid) : (Guid)p34.ParentId, Id = p34.Id, CreatedAt = p34.CreatedAt }).ToList(), Reviews = p33.Reviews.Select(p35 => new ReviewSDto() { Title = p35.Title, Comment = p35.Comment, Rate = p35.Rate, IsBuyer = p35.IsBuyer, ProductId = p35.ProductId, UserId = p35.UserId, Id = p35.Id, CreatedAt = p35.CreatedAt }).ToList(), Files = p33.Files.Select(p36 => new StorageFileSDto() { Name = p36.Name, FileLocation = p36.FileLocation, FileName = p36.FileName, IsHeader = p36.IsHeader, IsPrimary = p36.IsPrimary, FileType = p36.FileType, Id = p36.Id }).ToList(), Id = p33.Id, CreatedAt = p33.CreatedAt }; public static Product AdaptToProduct(this ProductSDto p37) { return p37 == null ? null : new Product() { PersianName = p37.PersianName, EnglishName = p37.EnglishName, Summery = p37.Summery, ExpertCheck = p37.ExpertCheck, Tags = p37.Tags, Warranty = p37.Warranty, Cost = p37.Cost, IsEnable = p37.IsEnable, BeDisplayed = p37.BeDisplayed, PackingCost = p37.PackingCost, Stock = p37.Stock, Rate = p37.Rate, ReviewCount = p37.ReviewCount, Viewed = p37.Viewed, MaxOrderCount = p37.MaxOrderCount, BrandId = p37.BrandId, Brand = new Brand() {Id = p37.BrandId}, CategoryId = p37.CategoryId, Category = new ProductCategory() { Name = p37.CategoryName, Id = p37.CategoryId }, Id = p37.Id, CreatedAt = p37.CreatedAt, ModifiedAt = p37.ModifiedAt }; } public static Product AdaptTo(this ProductSDto p38, Product p39) { if (p38 == null) { return null; } Product result = p39 ?? new Product(); result.PersianName = p38.PersianName; result.EnglishName = p38.EnglishName; result.Summery = p38.Summery; result.ExpertCheck = p38.ExpertCheck; result.Tags = p38.Tags; result.Warranty = p38.Warranty; result.Cost = p38.Cost; result.IsEnable = p38.IsEnable; result.BeDisplayed = p38.BeDisplayed; result.PackingCost = p38.PackingCost; result.Stock = p38.Stock; result.Rate = p38.Rate; result.ReviewCount = p38.ReviewCount; result.Viewed = p38.Viewed; result.MaxOrderCount = p38.MaxOrderCount; result.BrandId = p38.BrandId; result.Brand = funcMain15(new Never(), result.Brand, p38); result.CategoryId = p38.CategoryId; result.Category = funcMain16(new Never(), result.Category, p38); result.Id = p38.Id; result.CreatedAt = p38.CreatedAt; result.ModifiedAt = p38.ModifiedAt; return result; } public static ProductSDto AdaptToSDto(this Product p44) { return p44 == null ? null : new ProductSDto() { PersianName = p44.PersianName, EnglishName = p44.EnglishName, Summery = p44.Summery, ExpertCheck = p44.ExpertCheck, Tags = p44.Tags, Warranty = p44.Warranty, Cost = p44.Cost, IsEnable = p44.IsEnable, Stock = p44.Stock, MaxOrderCount = p44.MaxOrderCount, BeDisplayed = p44.BeDisplayed, PackingCost = p44.PackingCost, Rate = p44.Rate, ReviewCount = p44.ReviewCount, Viewed = p44.Viewed, MainImage = p44.Files.FirstOrDefault(funcMain17) != null ? p44.Files.FirstOrDefault(funcMain18).FileLocation : (p44.Files.Count > 0 ? p44.Files.FirstOrDefault().FileLocation : string.Empty), CategoryId = p44.CategoryId, BrandId = p44.BrandId, BrandName = p44.Brand == null ? null : p44.Brand.PersianName, CategoryName = p44.Category == null ? null : p44.Category.Name, ModifiedAt = p44.ModifiedAt, Id = p44.Id, CreatedAt = p44.CreatedAt }; } public static ProductSDto AdaptTo(this Product p45, ProductSDto p46) { if (p45 == null) { return null; } ProductSDto result = p46 ?? new ProductSDto(); result.PersianName = p45.PersianName; result.EnglishName = p45.EnglishName; result.Summery = p45.Summery; result.ExpertCheck = p45.ExpertCheck; result.Tags = p45.Tags; result.Warranty = p45.Warranty; result.Cost = p45.Cost; result.IsEnable = p45.IsEnable; result.Stock = p45.Stock; result.MaxOrderCount = p45.MaxOrderCount; result.BeDisplayed = p45.BeDisplayed; result.PackingCost = p45.PackingCost; result.Rate = p45.Rate; result.ReviewCount = p45.ReviewCount; result.Viewed = p45.Viewed; result.MainImage = p45.Files.FirstOrDefault(funcMain17) != null ? p45.Files.FirstOrDefault(funcMain18).FileLocation : (p45.Files.Count > 0 ? p45.Files.FirstOrDefault().FileLocation : string.Empty); result.CategoryId = p45.CategoryId; result.BrandId = p45.BrandId; result.BrandName = p45.Brand == null ? null : p45.Brand.PersianName; result.CategoryName = p45.Category == null ? null : p45.Category.Name; result.ModifiedAt = p45.ModifiedAt; result.Id = p45.Id; result.CreatedAt = p45.CreatedAt; return result; } public static Expression> ProjectToSDto => p47 => new ProductSDto() { PersianName = p47.PersianName, EnglishName = p47.EnglishName, Summery = p47.Summery, ExpertCheck = p47.ExpertCheck, Tags = p47.Tags, Warranty = p47.Warranty, Cost = p47.Cost, IsEnable = p47.IsEnable, Stock = p47.Stock, MaxOrderCount = p47.MaxOrderCount, BeDisplayed = p47.BeDisplayed, PackingCost = p47.PackingCost, Rate = p47.Rate, ReviewCount = p47.ReviewCount, Viewed = p47.Viewed, MainImage = p47.Files.FirstOrDefault(f => f.IsPrimary) != null ? p47.Files.FirstOrDefault(f => f.IsPrimary).FileLocation : (p47.Files.Count > 0 ? p47.Files.FirstOrDefault().FileLocation : string.Empty), CategoryId = p47.CategoryId, BrandId = p47.BrandId, BrandName = p47.Brand == null ? null : p47.Brand.PersianName, CategoryName = p47.Category == null ? null : p47.Category.Name, ModifiedAt = p47.ModifiedAt, Id = p47.Id, CreatedAt = p47.CreatedAt }; private static List funcMain1(List p2) { if (p2 == null) { return null; } List result = new List(p2.Count); int i = 0; int len = p2.Count; while (i < len) { SpecificationSDto item = p2[i]; result.Add(item == null ? null : new Specification() { Title = item.Title, Detail = item.Detail, Value = item.Value, IsFeature = item.IsFeature, ProductId = item.ProductId, ParentId = (Guid?)item.ParentId, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static List funcMain2(List p3) { if (p3 == null) { return null; } List result = new List(p3.Count); int i = 0; int len = p3.Count; while (i < len) { ReviewSDto item = p3[i]; result.Add(item == null ? null : new Review() { Title = item.Title, Comment = item.Comment, Rate = item.Rate, IsBuyer = item.IsBuyer, ProductId = item.ProductId, UserId = item.UserId, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static List funcMain3(List p4) { if (p4 == null) { return null; } List result = new List(p4.Count); int i = 0; int len = p4.Count; while (i < len) { StorageFileSDto item = p4[i]; result.Add(item == null ? null : new ProductStorageFile() { Name = item.Name, FileLocation = item.FileLocation, FileName = item.FileName, IsHeader = item.IsHeader, IsPrimary = item.IsPrimary, FileType = item.FileType, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static Brand funcMain4(Never p7, Brand p8, ProductLDto p5) { Brand result = p8 ?? new Brand(); result.Id = p5.BrandId; return result; } private static ProductCategory funcMain5(Never p9, ProductCategory p10, ProductLDto p5) { ProductCategory result = p10 ?? new ProductCategory(); result.Name = p5.CategoryName; result.Id = p5.CategoryId; return result; } private static List funcMain6(List p11, List p12) { if (p11 == null) { return null; } List result = new List(p11.Count); int i = 0; int len = p11.Count; while (i < len) { SpecificationSDto item = p11[i]; result.Add(item == null ? null : new Specification() { Title = item.Title, Detail = item.Detail, Value = item.Value, IsFeature = item.IsFeature, ProductId = item.ProductId, ParentId = (Guid?)item.ParentId, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static List funcMain7(List p13, List p14) { if (p13 == null) { return null; } List result = new List(p13.Count); int i = 0; int len = p13.Count; while (i < len) { ReviewSDto item = p13[i]; result.Add(item == null ? null : new Review() { Title = item.Title, Comment = item.Comment, Rate = item.Rate, IsBuyer = item.IsBuyer, ProductId = item.ProductId, UserId = item.UserId, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static List funcMain8(List p15, List p16) { if (p15 == null) { return null; } List result = new List(p15.Count); int i = 0; int len = p15.Count; while (i < len) { StorageFileSDto item = p15[i]; result.Add(item == null ? null : new ProductStorageFile() { Name = item.Name, FileLocation = item.FileLocation, FileName = item.FileName, IsHeader = item.IsHeader, IsPrimary = item.IsPrimary, FileType = item.FileType, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static List funcMain9(List p22) { if (p22 == null) { return null; } List result = new List(p22.Count); int i = 0; int len = p22.Count; while (i < len) { Specification item = p22[i]; result.Add(item == null ? null : new SpecificationSDto() { Title = item.Title, Detail = item.Detail, Value = item.Value, IsFeature = item.IsFeature, ProductId = item.ProductId, ParentId = item.ParentId == null ? default(Guid) : (Guid)item.ParentId, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static List funcMain10(List p23) { if (p23 == null) { return null; } List result = new List(p23.Count); int i = 0; int len = p23.Count; while (i < len) { Review item = p23[i]; result.Add(item == null ? null : new ReviewSDto() { Title = item.Title, Comment = item.Comment, Rate = item.Rate, IsBuyer = item.IsBuyer, ProductId = item.ProductId, UserId = item.UserId, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static List funcMain11(List p24) { if (p24 == null) { return null; } List result = new List(p24.Count); int i = 0; int len = p24.Count; while (i < len) { ProductStorageFile item = p24[i]; result.Add(item == null ? null : new StorageFileSDto() { Name = item.Name, FileLocation = item.FileLocation, FileName = item.FileName, IsHeader = item.IsHeader, IsPrimary = item.IsPrimary, FileType = item.FileType, Id = item.Id }); i++; } return result; } private static List funcMain12(List p27, List p28) { if (p27 == null) { return null; } List result = new List(p27.Count); int i = 0; int len = p27.Count; while (i < len) { Specification item = p27[i]; result.Add(item == null ? null : new SpecificationSDto() { Title = item.Title, Detail = item.Detail, Value = item.Value, IsFeature = item.IsFeature, ProductId = item.ProductId, ParentId = item.ParentId == null ? default(Guid) : (Guid)item.ParentId, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static List funcMain13(List p29, List p30) { if (p29 == null) { return null; } List result = new List(p29.Count); int i = 0; int len = p29.Count; while (i < len) { Review item = p29[i]; result.Add(item == null ? null : new ReviewSDto() { Title = item.Title, Comment = item.Comment, Rate = item.Rate, IsBuyer = item.IsBuyer, ProductId = item.ProductId, UserId = item.UserId, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static List funcMain14(List p31, List p32) { if (p31 == null) { return null; } List result = new List(p31.Count); int i = 0; int len = p31.Count; while (i < len) { ProductStorageFile item = p31[i]; result.Add(item == null ? null : new StorageFileSDto() { Name = item.Name, FileLocation = item.FileLocation, FileName = item.FileName, IsHeader = item.IsHeader, IsPrimary = item.IsPrimary, FileType = item.FileType, Id = item.Id }); i++; } return result; } private static Brand funcMain15(Never p40, Brand p41, ProductSDto p38) { Brand result = p41 ?? new Brand(); result.Id = p38.BrandId; return result; } private static ProductCategory funcMain16(Never p42, ProductCategory p43, ProductSDto p38) { ProductCategory result = p43 ?? new ProductCategory(); result.Name = p38.CategoryName; result.Id = p38.CategoryId; return result; } private static bool funcMain17(ProductStorageFile f) { return f.IsPrimary; } private static bool funcMain18(ProductStorageFile f) { return f.IsPrimary; } } }