private static async Task GetSummPayAllEmployes() { WriteLine(nameof(GetSummPayAllEmployes)); var client = new EmployeeAPIClient(_baseAddress); IEnumerable <EmployeeDTO> employees = await client.GetAllAsync(_employeeApi); if (employees.Count() > 0) { double summPay = employees.Sum(e => e.ToEmployee().AverageMonthlyWage()); WriteLine("Суммарная зарплатаа всех сотрудников за месяц: {0}", summPay); } WriteLine("Выполнено."); WriteLine(); }
private static async Task ReadAllEmployees() { WriteLine(nameof(ReadAllEmployees)); var client = new EmployeeAPIClient(_baseAddress); IEnumerable <EmployeeDTO> employees = await client.GetAllAsync(_employeeApi); if (employees.Count() > 0) { IEnumerable <EmployeeDTO> employeesSorted = employees .OrderByDescending(e => e.ToEmployee().AverageMonthlyWage()) .ThenBy(e => e.name) .ToList(); foreach (EmployeeDTO employee in employees) { WriteLine("{0} {1} {2} {3} {4}", employee.id, employee.name, employee.firstName, employee.patronymic, employee.ToEmployee().AverageMonthlyWage()); } double avgPay = employees.Average(e => e.ToEmployee().AverageMonthlyWage()); List <EmployeeDTO> employeesWithPayOverAvgPay = employees .Where(e => e.pay > avgPay) .ToList(); if (employeesWithPayOverAvgPay.Count() > 0) { FileStream stream = File.OpenWrite("EmployeesWithPayOverAvgPay.xml"); using (TextWriter writer = new StreamWriter(stream)) { XmlSerializer serializer = new XmlSerializer(typeof(EmployeeDTO[])); serializer.Serialize(writer, employeesWithPayOverAvgPay.ToArray()); } } } WriteLine("Выполнено."); WriteLine(); }