using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using Netina.Domain.Dtos.LargDtos; using Netina.Domain.Dtos.SmallDtos; using Netina.Domain.Entities.Blogs; namespace Netina.Domain.Mappers { public static partial class BlogCategoryMapper { public static BlogCategory AdaptToBlogCategory(this BlogCategoryLDto p1) { return p1 == null ? null : new BlogCategory() { Name = p1.Name, Description = p1.Description, Blogs = funcMain1(p1.Blogs), Id = p1.Id, CreatedAt = p1.CreatedAt }; } public static BlogCategory AdaptTo(this BlogCategoryLDto p3, BlogCategory p4) { if (p3 == null) { return null; } BlogCategory result = p4 ?? new BlogCategory(); result.Name = p3.Name; result.Description = p3.Description; result.Blogs = funcMain2(p3.Blogs, result.Blogs); result.Id = p3.Id; result.CreatedAt = p3.CreatedAt; return result; } public static Expression> ProjectToBlogCategory => p7 => new BlogCategory() { Name = p7.Name, Description = p7.Description, Blogs = p7.Blogs.Select(p8 => new Blog() { Title = p8.Title, Slug = p8.Slug, Tags = p8.Tags, ReadingTime = p8.ReadingTime, Summery = p8.Summery, IsSuggested = p8.IsSuggested, CategoryId = p8.CategoryId, Category = new BlogCategory() { Name = p8.CategoryName, Id = p8.CategoryId }, Id = p8.Id, CreatedAt = p8.CreatedAt, ModifiedAt = p8.ModifiedAt }).ToList(), Id = p7.Id, CreatedAt = p7.CreatedAt }; public static BlogCategoryLDto AdaptToLDto(this BlogCategory p9) { return p9 == null ? null : new BlogCategoryLDto() { Name = p9.Name, Description = p9.Description, Blogs = funcMain3(p9.Blogs), Id = p9.Id, CreatedAt = p9.CreatedAt }; } public static BlogCategoryLDto AdaptTo(this BlogCategory p11, BlogCategoryLDto p12) { if (p11 == null) { return null; } BlogCategoryLDto result = p12 ?? new BlogCategoryLDto(); result.Name = p11.Name; result.Description = p11.Description; result.Blogs = funcMain6(p11.Blogs, result.Blogs); result.Id = p11.Id; result.CreatedAt = p11.CreatedAt; return result; } public static Expression> ProjectToLDto => p15 => new BlogCategoryLDto() { Name = p15.Name, Description = p15.Description, Blogs = p15.Blogs.Select(p16 => new BlogSDto() { Title = p16.Title, Slug = p16.Slug, Tags = p16.Tags, ReadingTime = p16.ReadingTime, Summery = p16.Summery, IsSuggested = p16.IsSuggested, CategoryId = p16.CategoryId, CategoryName = p16.Category.Name, MainImage = p16.Files.Count > 0 && p16.Files.Any(f => f.IsPrimary) ? p16.Files.FirstOrDefault(f => f.IsPrimary).FileName : string.Empty, ModifiedAt = p16.ModifiedAt, Id = p16.Id, CreatedAt = p16.CreatedAt }).ToList(), Id = p15.Id, CreatedAt = p15.CreatedAt }; public static BlogCategory AdaptToBlogCategory(this BlogCategorySDto p17) { return p17 == null ? null : new BlogCategory() { Name = p17.Name, Description = p17.Description, Id = p17.Id, CreatedAt = p17.CreatedAt }; } public static BlogCategory AdaptTo(this BlogCategorySDto p18, BlogCategory p19) { if (p18 == null) { return null; } BlogCategory result = p19 ?? new BlogCategory(); result.Name = p18.Name; result.Description = p18.Description; result.Id = p18.Id; result.CreatedAt = p18.CreatedAt; return result; } public static BlogCategorySDto AdaptToSDto(this BlogCategory p20) { return p20 == null ? null : new BlogCategorySDto() { Name = p20.Name, BlogCount = funcMain7(p20.Blogs == null ? null : (int?)p20.Blogs.Count), Description = p20.Description, Id = p20.Id, CreatedAt = p20.CreatedAt }; } public static BlogCategorySDto AdaptTo(this BlogCategory p22, BlogCategorySDto p23) { if (p22 == null) { return null; } BlogCategorySDto result = p23 ?? new BlogCategorySDto(); result.Name = p22.Name; result.BlogCount = funcMain8(p22.Blogs == null ? null : (int?)p22.Blogs.Count, result.BlogCount); result.Description = p22.Description; result.Id = p22.Id; result.CreatedAt = p22.CreatedAt; return result; } public static Expression> ProjectToSDto => p26 => new BlogCategorySDto() { Name = p26.Name, BlogCount = p26.Blogs.Count, Description = p26.Description, Id = p26.Id, CreatedAt = p26.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) { BlogSDto item = p2[i]; result.Add(item == null ? null : new Blog() { Title = item.Title, Slug = item.Slug, Tags = item.Tags, ReadingTime = item.ReadingTime, Summery = item.Summery, IsSuggested = item.IsSuggested, CategoryId = item.CategoryId, Category = new BlogCategory() { Name = item.CategoryName, Id = item.CategoryId }, Id = item.Id, CreatedAt = item.CreatedAt, ModifiedAt = item.ModifiedAt }); 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) { BlogSDto item = p5[i]; result.Add(item == null ? null : new Blog() { Title = item.Title, Slug = item.Slug, Tags = item.Tags, ReadingTime = item.ReadingTime, Summery = item.Summery, IsSuggested = item.IsSuggested, CategoryId = item.CategoryId, Category = new BlogCategory() { Name = item.CategoryName, Id = item.CategoryId }, Id = item.Id, CreatedAt = item.CreatedAt, ModifiedAt = item.ModifiedAt }); 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) { Blog item = p10[i]; result.Add(item == null ? null : new BlogSDto() { Title = item.Title, Slug = item.Slug, Tags = item.Tags, ReadingTime = item.ReadingTime, Summery = item.Summery, IsSuggested = item.IsSuggested, CategoryId = item.CategoryId, CategoryName = item.Category == null ? null : item.Category.Name, MainImage = item.Files.Count > 0 && item.Files.Any(funcMain4) ? item.Files.FirstOrDefault(funcMain5).FileName : string.Empty, ModifiedAt = item.ModifiedAt, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static List funcMain6(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) { Blog item = p13[i]; result.Add(item == null ? null : new BlogSDto() { Title = item.Title, Slug = item.Slug, Tags = item.Tags, ReadingTime = item.ReadingTime, Summery = item.Summery, IsSuggested = item.IsSuggested, CategoryId = item.CategoryId, CategoryName = item.Category == null ? null : item.Category.Name, MainImage = item.Files.Count > 0 && item.Files.Any(funcMain4) ? item.Files.FirstOrDefault(funcMain5).FileName : string.Empty, ModifiedAt = item.ModifiedAt, Id = item.Id, CreatedAt = item.CreatedAt }); i++; } return result; } private static int funcMain7(int? p21) { return p21 == null ? 0 : (int)p21; } private static int funcMain8(int? p24, int p25) { return p24 == null ? 0 : (int)p24; } private static bool funcMain4(BlogStorageFile f) { return f.IsPrimary; } private static bool funcMain5(BlogStorageFile f) { return f.IsPrimary; } } }