Created
January 9, 2022 16:29
-
-
Save andrebaltieri/1d72c8d4db3e90f30ef5183b72acb3cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var orders = new List<Order> | |
{ | |
new("Order 1 -10 itens", GenerateOrderLines(9)), | |
new("Order 2 +10 itens ", GenerateOrderLines(12)), | |
new("Order 3 +10 itens", GenerateOrderLines(18)), | |
new("Order 4 +10 itens", GenerateOrderLines(22)) | |
}; | |
List<OrderLine> GenerateOrderLines(int quantity) | |
{ | |
var result = new List<OrderLine>(); | |
for (var i = 0; i < quantity; i++) | |
result.Add(new OrderLine($"Product {i}", i, i)); | |
return result; | |
} | |
var data = | |
from order in orders | |
let totalItems = order.OrderLines.Count | |
let total = order.OrderLines.Sum(x => x.Price) | |
where | |
totalItems > 10 && | |
total > 100 | |
select order; | |
foreach (var item in data) | |
Console.WriteLine($"{item.Number} - {item.OrderLines.Sum(x => x.Price)}"); | |
public record Order(string Number, List<OrderLine> OrderLines); | |
public record OrderLine(string Product, int Quantity, decimal Price); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment