using ShopOnline.Api.Entities; using ShopOnline.Models.Dtos; namespace ShopOnline.Api.Extensions { public static class DtoConversions { public static IEnumerable ConvertToDto(this IEnumerable products, IEnumerable productCategories) { return (from product in products join ProductCategory in productCategories on product.CategoryId equals ProductCategory.Id select new ProductDto { Id = product.Id, Name = product.Name, Description = product.Description, ImageURL = product.ImageURL, Price = product.Price, Quantity = product.Quantity, CategoryId = product.CategoryId, CategoryName = ProductCategory.Name }).ToList(); } public static ProductDto ConvertToDto(this Product product, ProductCategory productCategory) { return new ProductDto { Id = product.Id, Name = product.Name, Description= product.Description, ImageURL= product.ImageURL, Price= product.Price, Quantity= product.Quantity, CategoryId= product.CategoryId, CategoryName= productCategory.Name }; } } }