Пример #1
0
        public static async Task <PayrollViewModel> CreateAsync(
            DateTime from,
            DateTime to,
            string employeeId,
            IPayrollService services,
            IMapper mapper)
        {
            var model = await PayrollViewModel.CreateAsync(services);

            var employees = await services.GetEmployeesWihtPayrolls(employeeId);

            var employeessWithFilteredPaycheks = services.FilterEmployeesPaycheksByDate(from, to, employees);

            model.Employees               = mapper.Map <IEnumerable <Employee>, IEnumerable <EmployeeViewModel> >(employeessWithFilteredPaycheks);
            model.From                    = from;
            model.To                      = to;
            model.TotalPaycheksSum        = employees.Sum(e => e.Paycheks.Select(p => p.Total).Sum());
            model.TotalPaymentsSum        = employees.Sum(e => e.Paycheks.Select(p => p.GetPaidAmount()).Sum());
            model.TotalDiffrenceToBePayed = model.TotalPaycheksSum - model.TotalPaymentsSum;

            return(model);
        }