using LibraryDTO; using Model; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Stub { public static class Extensions { public static Ratings ToPoco(this RatingsDTO dto) => new Ratings() { Average = dto.Average, Count = dto.Count }; public static IEnumerable ToPocos(this IEnumerable dtos) => dtos.Select(dto => dto.ToPoco()); public static Contributor ToPoco(this ContributorDTO dto) => new Contributor { Name = dto.Name, Role = dto.Role }; public static IEnumerable ToPocos(this IEnumerable dtos) => dtos.Select(dto => dto.ToPoco()); public static Link ToPoco(this LinkDTO dto) => new Link { Title = dto.Title, Url = dto.Url }; public static IEnumerable ToPocos(this IEnumerable dtos) => dtos.Select(dto => dto.ToPoco()); public static Author ToPoco(this AuthorDTO dto) { var result = Mapper.AuthorsMapper.GetT(dto); if (result == null) { result = new Author { AlternateNames = dto.AlternateNames, Bio = dto.Bio, BirthDate = dto.BirthDate, DeathDate = dto.DeathDate, Id = dto.Id, Links = dto.Links.ToPocos().ToList(), Name = dto.Name }; } return result; } public static IEnumerable ToPocos(this IEnumerable dtos) => dtos.Select(dto => dto.ToPoco()); public static Work ToPoco(this WorkDTO dto) { var result = Mapper.WorksMapper.GetT(dto); if (result == null) { result = new Work { Authors = dto.Authors.ToPocos().ToList(), Description = dto.Description, Id = dto.Id, Ratings = dto.Ratings.ToPoco(), Subjects = dto.Subjects, Title = dto.Title }; } return result; } public static IEnumerable ToPocos(this IEnumerable dtos) => dtos.Select(dto => dto.ToPoco()); public static Book ToPoco(this BookDTO dto) { var result = Mapper.BooksMapper.GetT(dto); if (result == null) { result = new Book { Authors = dto.Authors.ToPocos().ToList(), Contributors = dto.Contributors.ToPocos().ToList(), Format = dto.Format, Id = dto.Id, ISBN13 = dto.ISBN13, Language = dto.Language.ToModel(), NbPages = dto.NbPages, PublishDate = dto.PublishDate, Publishers = dto.Publishers, Series = dto.Series, Title = dto.Title, Works = dto.Works.ToPocos().ToList() }; } return result; } public static IEnumerable ToPocos(this IEnumerable dtos) => dtos.Select(dto => dto.ToPoco()); } }