Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.09 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApplication2
  6. {
  7.     public class Test
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             var bills = new List<Bill>
  12.             {
  13.                 new Bill {date = DateTime.Now.Date.AddDays(-5), bill = 111, value = 10000},
  14.                 new Bill {date = DateTime.Now.Date.AddDays(-4), bill = 111, value = 15000},
  15.                 new Bill {date = DateTime.Now.Date.AddDays(-4), bill = 222, value = 10000},
  16.                 new Bill {date = DateTime.Now.Date.AddDays(-5), bill = 333, value = 15000},
  17.                 new Bill {date = DateTime.Now.Date.AddDays(-5), bill = 444, value = 10000},
  18.                 new Bill {date = DateTime.Now.Date.AddDays(-5), bill = 555, value = 15000},
  19.                 new Bill {date = DateTime.Now.Date.AddDays(-1), bill = 222, value = 15000},
  20.                 new Bill {date = DateTime.Now.Date.AddDays(-1), bill = 111, value = 10000}
  21.             };
  22.  
  23.  
  24.             var clientBills = new List<ClientBill>
  25.             {
  26.                 new ClientBill {LastName = "Иванов", billNumber = 111, city = "Москва"},
  27.                 new ClientBill {LastName = "Иванов", billNumber = 222, city = "Москва"},
  28.                 new ClientBill {LastName = "Петров", billNumber = 333, city = "не Москва"},
  29.                 new ClientBill {LastName = "Петров", billNumber = 444, city = "не Москва"},
  30.                 new ClientBill {LastName = "Сидоров", billNumber = 555, city = "Москва"}
  31.             };
  32.  
  33.             var result = new Dictionary<string, double>();
  34.  
  35.             foreach (var client in clientBills.Where(x => x.city == "Москва").Select(x => x.LastName).Distinct())
  36.             {
  37.                 var sum =
  38.                     clientBills.Where(x => x.LastName == client)
  39.                         .Select(x => x.billNumber)
  40.                         .Sum(
  41.                             bill =>
  42.                                 bills.Select(x => x.bill)
  43.                                     .Distinct()
  44.                                     .Select(
  45.                                         b =>
  46.                                             bills.Where(x => x.bill == b)
  47.                                                 .OrderByDescending(x => x.date)
  48.                                                 .FirstOrDefault())
  49.                                     .Where(x => x.bill == bill)
  50.                                     .Select(x => x.value)
  51.                                     .FirstOrDefault());
  52.                 if (sum > 20000)
  53.                     result.Add(client, sum);
  54.             }
  55.  
  56.  
  57.             Console.Write("Hello");
  58.             Console.Read();
  59.         }
  60.     }
  61.  
  62.     public class Bill
  63.     {
  64.         public DateTime date { get; set; }
  65.         public int bill { get; set; }
  66.         public double value { get; set; }
  67.     }
  68.  
  69.     public class ClientBill
  70.     {
  71.         public string LastName { get; set; }
  72.         public int billNumber { get; set; }
  73.         public string city { get; set; }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement