List<ProductDTO> IService1.GetProducts() { List<Product> products = new List<Product>(); // Ürün Mapper ProductMapper productMapper = new ProductMapper(); // Tüm ürünleri yükle products = productMapper.GetAllProducts(); // Ürünleri dönüştür ve geri gönder return ProductConverter.CretateProductDto(products); }
public static List<ProductDTO> CretateProductDto(List<Product> products) { List<ProductDTO> productsDto = new List<ProductDTO>(); ProductMapper mapper = new ProductMapper(); foreach (Product pr in products) { ProductDTO dto = new ProductDTO(); dto.Id = pr.ProductId; dto.ProductName = pr.ProductName; dto.ProductCategoryId = pr.ProductCategoryId; dto.ProductCategoryName = mapper.GetProductCategory(pr.ProductCategoryId).CategoryName; productsDto.Add(dto); } return productsDto; }