Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace ConsoleApplication2
- {
- public class Test
- {
- public static void Main(string[] args)
- {
- var bills = new List<Bill>
- {
- new Bill {date = DateTime.Now.Date.AddDays(-5), bill = 111, value = 10000},
- new Bill {date = DateTime.Now.Date.AddDays(-4), bill = 111, value = 15000},
- new Bill {date = DateTime.Now.Date.AddDays(-4), bill = 222, value = 10000},
- new Bill {date = DateTime.Now.Date.AddDays(-5), bill = 333, value = 15000},
- new Bill {date = DateTime.Now.Date.AddDays(-5), bill = 444, value = 10000},
- new Bill {date = DateTime.Now.Date.AddDays(-5), bill = 555, value = 15000},
- new Bill {date = DateTime.Now.Date.AddDays(-1), bill = 222, value = 15000},
- new Bill {date = DateTime.Now.Date.AddDays(-1), bill = 111, value = 10000}
- };
- var clientBills = new List<ClientBill>
- {
- new ClientBill {LastName = "Иванов", billNumber = 111, city = "Москва"},
- new ClientBill {LastName = "Иванов", billNumber = 222, city = "Москва"},
- new ClientBill {LastName = "Петров", billNumber = 333, city = "не Москва"},
- new ClientBill {LastName = "Петров", billNumber = 444, city = "не Москва"},
- new ClientBill {LastName = "Сидоров", billNumber = 555, city = "Москва"}
- };
- var result =
- clientBills.Where(x => x.city == "Москва")
- .Select(x => x.LastName)
- .Distinct()
- .ToDictionary(client => client,
- client =>
- clientBills.Where(x => x.LastName == client)
- .Select(x => x.billNumber)
- .Sum(
- bill =>
- bills.Select(x => x.bill)
- .Distinct()
- .Select(
- b =>
- bills.Where(x => x.bill == b)
- .OrderByDescending(x => x.date)
- .FirstOrDefault())
- .Where(x => x.bill == bill)
- .Select(x => x.value)
- .FirstOrDefault())).Where(x => x.Value > 20000);
- }
- }
- public class Bill
- {
- public DateTime date { get; set; }
- public int bill { get; set; }
- public double value { get; set; }
- }
- public class ClientBill
- {
- public string LastName { get; set; }
- public int billNumber { get; set; }
- public string city { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement