38 lines
1.3 KiB
C#
38 lines
1.3 KiB
C#
using HomeLibrary.Api.Entities;
|
|
using HomeLibrary.Models.Dtos;
|
|
|
|
namespace HomeLibrary.Api.Extensions
|
|
{
|
|
public static class DtoConversions
|
|
{
|
|
public static IEnumerable<CompleteBookDto> ConvertToDto(this IEnumerable<Book> books, IEnumerable<Author> authors)
|
|
{
|
|
return (from book in books
|
|
join author in authors
|
|
on book.AuthorId equals author.Id
|
|
select new CompleteBookDto
|
|
{
|
|
BookId = book.Id,
|
|
AuthorId = author.Id,
|
|
AuthorName = author.Name,
|
|
Title = book.Title,
|
|
Series = book.Series,
|
|
BookNumber = book.BookNumber
|
|
}).ToList();
|
|
}
|
|
|
|
public static IEnumerable<BookDto> ConvertToDto(this IEnumerable<Book> books)
|
|
{
|
|
return (from book in books
|
|
select new BookDto
|
|
{
|
|
Id = book.Id,
|
|
AuthorId = book.AuthorId,
|
|
Title = book.Title,
|
|
Series = book.Series,
|
|
BookNumber = book.BookNumber
|
|
}).ToList();
|
|
}
|
|
}
|
|
}
|