using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using Mapster.Models; using Netina.Domain.Dtos.LargDtos; using Netina.Domain.Dtos.ResponseDtos.Torob; using Netina.Domain.Dtos.SmallDtos; using Netina.Domain.Entities.Brands; using Netina.Domain.Entities.ProductCategories; using Netina.Domain.Entities.Products; using Netina.Domain.Entities.Reviews; using Netina.Domain.Entities.Users; namespace Netina.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, Slug = p1.Slug, 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, AuthorId = p1.AuthorId, Author = new ApplicationUser() {Id = p1.AuthorId}, 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.Slug = p5.Slug; 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.AuthorId = p5.AuthorId; result.Author = funcMain5(new Never(), result.Author, p5); result.Category = funcMain6(new Never(), result.Category, p5); result.Specifications = funcMain7(p5.Specifications, result.Specifications); result.Reviews = funcMain8(p5.Reviews, result.Reviews); result.Files = funcMain9(p5.Files, result.Files); result.Id = p5.Id; result.CreatedAt = p5.CreatedAt; return result; } public static Expression> ProjectToProduct => p19 => new Product() { PersianName = p19.PersianName, EnglishName = p19.EnglishName, Slug = p19.Slug, Summery = p19.Summery, ExpertCheck = p19.ExpertCheck, Tags = p19.Tags, Warranty = p19.Warranty, Cost = p19.Cost, BeDisplayed = p19.BeDisplayed, PackingCost = p19.PackingCost, Stock = p19.Stock, HasExpressDelivery = p19.HasExpressDelivery, MaxOrderCount = p19.MaxOrderCount, BrandId = p19.BrandId, Brand = new Brand() {Id = p19.BrandId}, CategoryId = p19.CategoryId, AuthorId = p19.AuthorId, Author = new ApplicationUser() {Id = p19.AuthorId}, Category = new ProductCategory() { Name = p19.CategoryName, Id = p19.CategoryId }, Specifications = p19.Specifications.Select(p20 => new Specification() { Title = p20.Title, Detail = p20.Detail, Value = p20.Value, IsFeature = p20.IsFeature, ProductId = p20.ProductId, ParentId = (Guid?)p20.ParentId, Id = p20.Id, CreatedAt = p20.CreatedAt }).ToList(), Reviews = p19.Reviews.Select(p21 => new Review() { Title = p21.Title, Comment = p21.Comment, Rate = p21.Rate, IsBuyer = p21.IsBuyer, ProductId = p21.ProductId, UserId = p21.UserId, Id = p21.Id, CreatedAt = p21.CreatedAt }).ToList(), Files = p19.Files.Select(p22 => new ProductStorageFile() { Name = p22.Name, FileLocation = p22.FileLocation, FileName = p22.FileName, IsHeader = p22.IsHeader, IsPrimary = p22.IsPrimary, FileType = p22.FileType, Id = p22.Id, CreatedAt = p22.CreatedAt }).ToList(), Id = p19.Id, CreatedAt = p19.CreatedAt }; public static ProductLDto AdaptToLDto(this Product p23) { return p23 == null ? null : new ProductLDto() { PersianName = p23.PersianName, EnglishName = p23.EnglishName, Summery = p23.Summery, ExpertCheck = p23.ExpertCheck, Tags = p23.Tags, Slug = p23.Slug, Warranty = p23.Warranty, BeDisplayed = p23.BeDisplayed, HasExpressDelivery = p23.HasExpressDelivery, Cost = p23.Cost, PackingCost = p23.PackingCost, MaxOrderCount = p23.MaxOrderCount, Stock = p23.Stock, BrandId = p23.BrandId, BrandName = p23.Brand == null ? null : p23.Brand.PersianName, CategoryId = p23.CategoryId, CategoryName = p23.Category == null ? null : p23.Category.Name, Specifications = funcMain10(p23.Specifications), Reviews = funcMain11(p23.Reviews), Files = funcMain12(p23.Files), AuthorId = p23.AuthorId, AuthorFullName = p23.Author != null ? p23.Author.FirstName + " " + p23.Author.LastName : string.Empty, Id = p23.Id, CreatedAt = p23.CreatedAt }; } public static ProductLDto AdaptTo(this Product p27, ProductLDto p28) { if (p27 == null) { return null; } ProductLDto result = p28 ?? new ProductLDto(); result.PersianName = p27.PersianName; result.EnglishName = p27.EnglishName; result.Summery = p27.Summery; result.ExpertCheck = p27.ExpertCheck; result.Tags = p27.Tags; result.Slug = p27.Slug; result.Warranty = p27.Warranty; result.BeDisplayed = p27.BeDisplayed; result.HasExpressDelivery = p27.HasExpressDelivery; result.Cost = p27.Cost; result.PackingCost = p27.PackingCost; result.MaxOrderCount = p27.MaxOrderCount; result.Stock = p27.Stock; result.BrandId = p27.BrandId; result.BrandName = p27.Brand == null ? null : p27.Brand.PersianName; result.CategoryId = p27.CategoryId; result.CategoryName = p27.Category == null ? null : p27.Category.Name; result.Specifications = funcMain13(p27.Specifications, result.Specifications); result.Reviews = funcMain14(p27.Reviews, result.Reviews); result.Files = funcMain15(p27.Files, result.Files); result.AuthorId = p27.AuthorId; result.AuthorFullName = p27.Author != null ? p27.Author.FirstName + " " + p27.Author.LastName : string.Empty; result.Id = p27.Id; result.CreatedAt = p27.CreatedAt; return result; } public static Expression> ProjectToLDto => p35 => new ProductLDto() { PersianName = p35.PersianName, EnglishName = p35.EnglishName, Summery = p35.Summery, ExpertCheck = p35.ExpertCheck, Tags = p35.Tags, Slug = p35.Slug, Warranty = p35.Warranty, BeDisplayed = p35.BeDisplayed, HasExpressDelivery = p35.HasExpressDelivery, Cost = p35.Cost, PackingCost = p35.PackingCost, MaxOrderCount = p35.MaxOrderCount, Stock = p35.Stock, BrandId = p35.BrandId, BrandName = p35.Brand == null ? null : p35.Brand.PersianName, CategoryId = p35.CategoryId, CategoryName = p35.Category == null ? null : p35.Category.Name, Specifications = p35.Specifications.Select(p36 => new SpecificationSDto() { Title = p36.Title, Detail = p36.Detail, Value = p36.Value, IsFeature = p36.IsFeature, ProductId = p36.ProductId, ParentId = p36.ParentId == null ? default(Guid) : (Guid)p36.ParentId, Id = p36.Id, CreatedAt = p36.CreatedAt }).ToList(), Reviews = p35.Reviews.Select(p37 => new ReviewSDto() { Title = p37.Title, Comment = p37.Comment, Rate = p37.Rate, IsBuyer = p37.IsBuyer, ProductId = p37.ProductId, UserId = p37.UserId, Id = p37.Id, CreatedAt = p37.CreatedAt }).ToList(), Files = p35.Files.Select(p38 => new StorageFileSDto() { Name = p38.Name, FileLocation = p38.FileLocation, FileName = p38.FileName, IsHeader = p38.IsHeader, IsPrimary = p38.IsPrimary, FileType = p38.FileType, Id = p38.Id }).ToList(), AuthorId = p35.AuthorId, AuthorFullName = p35.Author != null ? p35.Author.FirstName + " " + p35.Author.LastName : string.Empty, Id = p35.Id, CreatedAt = p35.CreatedAt }; public static Product AdaptToProduct(this ProductSDto p39) { return p39 == null ? null : new Product() { PersianName = p39.PersianName, EnglishName = p39.EnglishName, Slug = p39.Slug, Summery = p39.Summery, ExpertCheck = p39.ExpertCheck, Tags = p39.Tags, Warranty = p39.Warranty, Cost = p39.Cost, IsEnable = p39.IsEnable, BeDisplayed = p39.BeDisplayed, PackingCost = p39.PackingCost, Stock = p39.Stock, Rate = p39.Rate, ReviewCount = p39.ReviewCount, Viewed = p39.Viewed, MaxOrderCount = p39.MaxOrderCount, BrandId = p39.BrandId, Brand = new Brand() {Id = p39.BrandId}, CategoryId = p39.CategoryId, AuthorId = p39.AuthorId, Author = new ApplicationUser() {Id = p39.AuthorId}, Category = new ProductCategory() { Name = p39.CategoryName, Id = p39.CategoryId }, Id = p39.Id, CreatedAt = p39.CreatedAt, ModifiedAt = p39.ModifiedAt }; } public static Product AdaptTo(this ProductSDto p40, Product p41) { if (p40 == null) { return null; } Product result = p41 ?? new Product(); result.PersianName = p40.PersianName; result.EnglishName = p40.EnglishName; result.Slug = p40.Slug; result.Summery = p40.Summery; result.ExpertCheck = p40.ExpertCheck; result.Tags = p40.Tags; result.Warranty = p40.Warranty; result.Cost = p40.Cost; result.IsEnable = p40.IsEnable; result.BeDisplayed = p40.BeDisplayed; result.PackingCost = p40.PackingCost; result.Stock = p40.Stock; result.Rate = p40.Rate; result.ReviewCount = p40.ReviewCount; result.Viewed = p40.Viewed; result.MaxOrderCount = p40.MaxOrderCount; result.BrandId = p40.BrandId; result.Brand = funcMain16(new Never(), result.Brand, p40); result.CategoryId = p40.CategoryId; result.AuthorId = p40.AuthorId; result.Author = funcMain17(new Never(), result.Author, p40); result.Category = funcMain18(new Never(), result.Category, p40); result.Id = p40.Id; result.CreatedAt = p40.CreatedAt; result.ModifiedAt = p40.ModifiedAt; return result; } public static ProductSDto AdaptToSDto(this Product p48) { return p48 == null ? null : new ProductSDto() { PersianName = p48.PersianName, Slug = p48.Slug, EnglishName = p48.EnglishName, Summery = p48.Summery, ExpertCheck = p48.ExpertCheck, Tags = p48.Tags, Warranty = p48.Warranty, Cost = p48.Cost, IsEnable = p48.IsEnable, Stock = p48.Stock, MaxOrderCount = p48.MaxOrderCount, BeDisplayed = p48.BeDisplayed, PackingCost = p48.PackingCost, Rate = p48.Rate, ReviewCount = p48.ReviewCount, Viewed = p48.Viewed, MainImage = p48.Files.FirstOrDefault(funcMain19) != null ? p48.Files.FirstOrDefault(funcMain20).FileLocation : (p48.Files.Count > 0 ? p48.Files.FirstOrDefault().FileLocation : string.Empty), CategoryId = p48.CategoryId, BrandId = p48.BrandId, BrandName = p48.Brand == null ? null : p48.Brand.PersianName, CategoryName = p48.Category == null ? null : p48.Category.Name, ModifiedAt = p48.ModifiedAt, AuthorId = p48.AuthorId, AuthorFullName = p48.Author != null ? p48.Author.FirstName + " " + p48.Author.LastName : string.Empty, Id = p48.Id, CreatedAt = p48.CreatedAt }; } public static ProductSDto AdaptTo(this Product p49, ProductSDto p50) { if (p49 == null) { return null; } ProductSDto result = p50 ?? new ProductSDto(); result.PersianName = p49.PersianName; result.Slug = p49.Slug; result.EnglishName = p49.EnglishName; result.Summery = p49.Summery; result.ExpertCheck = p49.ExpertCheck; result.Tags = p49.Tags; result.Warranty = p49.Warranty; result.Cost = p49.Cost; result.IsEnable = p49.IsEnable; result.Stock = p49.Stock; result.MaxOrderCount = p49.MaxOrderCount; result.BeDisplayed = p49.BeDisplayed; result.PackingCost = p49.PackingCost; result.Rate = p49.Rate; result.ReviewCount = p49.ReviewCount; result.Viewed = p49.Viewed; result.MainImage = p49.Files.FirstOrDefault(funcMain19) != null ? p49.Files.FirstOrDefault(funcMain20).FileLocation : (p49.Files.Count > 0 ? p49.Files.FirstOrDefault().FileLocation : string.Empty); result.CategoryId = p49.CategoryId; result.BrandId = p49.BrandId; result.BrandName = p49.Brand == null ? null : p49.Brand.PersianName; result.CategoryName = p49.Category == null ? null : p49.Category.Name; result.ModifiedAt = p49.ModifiedAt; result.AuthorId = p49.AuthorId; result.AuthorFullName = p49.Author != null ? p49.Author.FirstName + " " + p49.Author.LastName : string.Empty; result.Id = p49.Id; result.CreatedAt = p49.CreatedAt; return result; } public static Expression> ProjectToSDto => p51 => new ProductSDto() { PersianName = p51.PersianName, Slug = p51.Slug, EnglishName = p51.EnglishName, Summery = p51.Summery, ExpertCheck = p51.ExpertCheck, Tags = p51.Tags, Warranty = p51.Warranty, Cost = p51.Cost, IsEnable = p51.IsEnable, Stock = p51.Stock, MaxOrderCount = p51.MaxOrderCount, BeDisplayed = p51.BeDisplayed, PackingCost = p51.PackingCost, Rate = p51.Rate, ReviewCount = p51.ReviewCount, Viewed = p51.Viewed, MainImage = p51.Files.FirstOrDefault(f => f.IsPrimary) != null ? p51.Files.FirstOrDefault(f => f.IsPrimary).FileLocation : (p51.Files.Count > 0 ? p51.Files.FirstOrDefault().FileLocation : string.Empty), CategoryId = p51.CategoryId, BrandId = p51.BrandId, BrandName = p51.Brand == null ? null : p51.Brand.PersianName, CategoryName = p51.Category == null ? null : p51.Category.Name, ModifiedAt = p51.ModifiedAt, AuthorId = p51.AuthorId, AuthorFullName = p51.Author != null ? p51.Author.FirstName + " " + p51.Author.LastName : string.Empty, Id = p51.Id, CreatedAt = p51.CreatedAt }; public static Expression> ProjectToTorobResponseDto => p52 => new TorobProductResponseDto() { product_id = p52.Id.ToString(), price = p52.Cost, availibility = p52.IsEnable }; 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 ApplicationUser funcMain5(Never p9, ApplicationUser p10, ProductLDto p5) { ApplicationUser result = p10 ?? new ApplicationUser(); result.Id = p5.AuthorId; return result; } private static ProductCategory funcMain6(Never p11, ProductCategory p12, ProductLDto p5) { ProductCategory result = p12 ?? new ProductCategory(); result.Name = p5.CategoryName; result.Id = p5.CategoryId; 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) { SpecificationSDto item = p13[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 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) { ReviewSDto item = p15[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 funcMain9(List p17, List p18) { if (p17 == null) { return null; } List result = new List(p17.Count); int i = 0; int len = p17.Count; while (i < len) { StorageFileSDto item = p17[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 funcMain10(List p24) { if (p24 == null) { return null; } List result = new List(p24.Count); int i = 0; int len = p24.Count; while (i < len) { Specification item = p24[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 funcMain11(List p25) { if (p25 == null) { return null; } List result = new List(p25.Count); int i = 0; int len = p25.Count; while (i < len) { Review item = p25[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 funcMain12(List p26) { if (p26 == null) { return null; } List result = new List(p26.Count); int i = 0; int len = p26.Count; while (i < len) { ProductStorageFile item = p26[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 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) { Specification item = p29[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 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) { Review item = p31[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 funcMain15(List p33, List p34) { if (p33 == null) { return null; } List result = new List(p33.Count); int i = 0; int len = p33.Count; while (i < len) { ProductStorageFile item = p33[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 funcMain16(Never p42, Brand p43, ProductSDto p40) { Brand result = p43 ?? new Brand(); result.Id = p40.BrandId; return result; } private static ApplicationUser funcMain17(Never p44, ApplicationUser p45, ProductSDto p40) { ApplicationUser result = p45 ?? new ApplicationUser(); result.Id = p40.AuthorId; return result; } private static ProductCategory funcMain18(Never p46, ProductCategory p47, ProductSDto p40) { ProductCategory result = p47 ?? new ProductCategory(); result.Name = p40.CategoryName; result.Id = p40.CategoryId; return result; } private static bool funcMain19(ProductStorageFile f) { return f.IsPrimary; } private static bool funcMain20(ProductStorageFile f) { return f.IsPrimary; } } }