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.Blogs; namespace NetinaShop.Domain.Mappers { public static partial class BlogMapper { public static Blog AdaptToBlog(this BlogLDto p1) { return p1 == null ? null : new Blog() { Title = p1.Title, Content = p1.Content, Tags = p1.Tags, ReadingTime = p1.ReadingTime, Summery = p1.Summery, IsSuggested = p1.IsSuggested, CategoryId = p1.CategoryId, Files = funcMain1(p1.Files), Id = p1.Id, CreatedAt = p1.CreatedAt }; } public static Blog AdaptTo(this BlogLDto p3, Blog p4) { if (p3 == null) { return null; } Blog result = p4 ?? new Blog(); result.Title = p3.Title; result.Content = p3.Content; result.Tags = p3.Tags; result.ReadingTime = p3.ReadingTime; result.Summery = p3.Summery; result.IsSuggested = p3.IsSuggested; result.CategoryId = p3.CategoryId; result.Files = funcMain2(p3.Files, result.Files); result.Id = p3.Id; result.CreatedAt = p3.CreatedAt; return result; } public static Expression> ProjectToBlog => p7 => new Blog() { Title = p7.Title, Content = p7.Content, Tags = p7.Tags, ReadingTime = p7.ReadingTime, Summery = p7.Summery, IsSuggested = p7.IsSuggested, CategoryId = p7.CategoryId, Files = p7.Files.Select(p8 => new BlogStorageFile() { Name = p8.Name, FileLocation = p8.FileLocation, FileName = p8.FileName, IsHeader = p8.IsHeader, IsPrimary = p8.IsPrimary, FileType = p8.FileType, Id = p8.Id, CreatedAt = p8.CreatedAt }).ToList(), Id = p7.Id, CreatedAt = p7.CreatedAt }; public static BlogLDto AdaptToLDto(this Blog p9) { return p9 == null ? null : new BlogLDto() { Title = p9.Title, Content = p9.Content, Tags = p9.Tags, ReadingTime = p9.ReadingTime, Summery = p9.Summery, IsSuggested = p9.IsSuggested, CategoryId = p9.CategoryId, CategoryName = p9.Category == null ? null : p9.Category.Name, Files = funcMain3(p9.Files), Id = p9.Id, CreatedAt = p9.CreatedAt }; } public static BlogLDto AdaptTo(this Blog p11, BlogLDto p12) { if (p11 == null) { return null; } BlogLDto result = p12 ?? new BlogLDto(); result.Title = p11.Title; result.Content = p11.Content; result.Tags = p11.Tags; result.ReadingTime = p11.ReadingTime; result.Summery = p11.Summery; result.IsSuggested = p11.IsSuggested; result.CategoryId = p11.CategoryId; result.CategoryName = p11.Category == null ? null : p11.Category.Name; result.Files = funcMain4(p11.Files, result.Files); result.Id = p11.Id; result.CreatedAt = p11.CreatedAt; return result; } public static Expression> ProjectToLDto => p15 => new BlogLDto() { Title = p15.Title, Content = p15.Content, Tags = p15.Tags, ReadingTime = p15.ReadingTime, Summery = p15.Summery, IsSuggested = p15.IsSuggested, CategoryId = p15.CategoryId, CategoryName = p15.Category.Name, Files = p15.Files.Select(p16 => new StorageFileSDto() { Name = p16.Name, FileLocation = p16.FileLocation, FileName = p16.FileName, IsHeader = p16.IsHeader, IsPrimary = p16.IsPrimary, FileType = p16.FileType, Id = p16.Id }).ToList(), Id = p15.Id, CreatedAt = p15.CreatedAt }; public static Blog AdaptToBlog(this BlogSDto p17) { return p17 == null ? null : new Blog() { Title = p17.Title, Content = p17.Content, Tags = p17.Tags, ReadingTime = p17.ReadingTime, Summery = p17.Summery, IsSuggested = p17.IsSuggested, CategoryId = p17.CategoryId, Category = new BlogCategory() { Name = p17.CategoryName, Id = p17.CategoryId }, Id = p17.Id, CreatedAt = p17.CreatedAt }; } public static Blog AdaptTo(this BlogSDto p18, Blog p19) { if (p18 == null) { return null; } Blog result = p19 ?? new Blog(); result.Title = p18.Title; result.Content = p18.Content; result.Tags = p18.Tags; result.ReadingTime = p18.ReadingTime; result.Summery = p18.Summery; result.IsSuggested = p18.IsSuggested; result.CategoryId = p18.CategoryId; result.Category = funcMain5(new Never(), result.Category, p18); result.Id = p18.Id; result.CreatedAt = p18.CreatedAt; return result; } public static BlogSDto AdaptToSDto(this Blog p22) { return p22 == null ? null : new BlogSDto() { Title = p22.Title, Content = p22.Content, Tags = p22.Tags, ReadingTime = p22.ReadingTime, Summery = p22.Summery, IsSuggested = p22.IsSuggested, CategoryId = p22.CategoryId, CategoryName = p22.Category == null ? null : p22.Category.Name, HeaderFileName = p22.Files.Count > 0 && p22.Files.Any(funcMain6) ? p22.Files.FirstOrDefault(funcMain7).FileName : string.Empty, Id = p22.Id, CreatedAt = p22.CreatedAt }; } public static BlogSDto AdaptTo(this Blog p23, BlogSDto p24) { if (p23 == null) { return null; } BlogSDto result = p24 ?? new BlogSDto(); result.Title = p23.Title; result.Content = p23.Content; result.Tags = p23.Tags; result.ReadingTime = p23.ReadingTime; result.Summery = p23.Summery; result.IsSuggested = p23.IsSuggested; result.CategoryId = p23.CategoryId; result.CategoryName = p23.Category == null ? null : p23.Category.Name; result.HeaderFileName = p23.Files.Count > 0 && p23.Files.Any(funcMain6) ? p23.Files.FirstOrDefault(funcMain7).FileName : string.Empty; result.Id = p23.Id; result.CreatedAt = p23.CreatedAt; return result; } public static Expression> ProjectToSDto => p25 => new BlogSDto() { Title = p25.Title, Content = p25.Content, Tags = p25.Tags, ReadingTime = p25.ReadingTime, Summery = p25.Summery, IsSuggested = p25.IsSuggested, CategoryId = p25.CategoryId, CategoryName = p25.Category.Name, HeaderFileName = p25.Files.Count > 0 && p25.Files.Any(f => f.IsHeader) ? p25.Files.FirstOrDefault(f => f.IsHeader).FileName : string.Empty, Id = p25.Id, CreatedAt = p25.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) { StorageFileSDto item = p2[i]; result.Add(item == null ? null : new BlogStorageFile() { 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 funcMain2(List p5, List p6) { if (p5 == null) { return null; } List result = new List(p5.Count); int i = 0; int len = p5.Count; while (i < len) { StorageFileSDto item = p5[i]; result.Add(item == null ? null : new BlogStorageFile() { 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 funcMain3(List p10) { if (p10 == null) { return null; } List result = new List(p10.Count); int i = 0; int len = p10.Count; while (i < len) { BlogStorageFile item = p10[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 funcMain4(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) { BlogStorageFile item = p13[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 BlogCategory funcMain5(Never p20, BlogCategory p21, BlogSDto p18) { BlogCategory result = p21 ?? new BlogCategory(); result.Name = p18.CategoryName; result.Id = p18.CategoryId; return result; } private static bool funcMain6(BlogStorageFile f) { return f.IsHeader; } private static bool funcMain7(BlogStorageFile f) { return f.IsHeader; } } }