コード例 #1
0
        public static ProjectDetailsDto MapToDetailsDto(ProjectDto dto)
        {
            return(new ProjectDetailsDto
            {
                Id = dto.Id,
                Active = dto.Active,
                Description = dto.Description,
                EndDate = dto.EndDate,
                IsAccepted = dto.IsAccepted,
                IsDone = dto.IsDone,
                IsFixedPrice = dto.IsFixedPrice,
                Price = dto.Price,
                ESTdriving = dto.ESTdriving,
                StartDate = dto.StartDate,
                Rowversion = dto.Rowversion,
                CustomerId = dto.CustomerId,
                Customer = dto.CustomerDto,

                ProjectDrivings = dto.ProjectDrivingDtos.GroupBy(PD => PD.UnitPrice)
                                  .Select(PD => new ProjectDrivingDto
                {
                    Amount = PD.Sum(a => a.Amount),
                    EmployeeId = PD.First().EmployeeId,
                    Employee = PD.First().Employee,
                    ProjectId = PD.First().ProjectId,
                    UnitPrice = PD.First().UnitPrice
                }).ToList(),

                TotalUsedDriving = dto.ProjectDrivingDtos.Sum(UI => UI.Amount * UI.UnitPrice),

                ProjectEmployees = dto.ProjectEmployeeDtos.GroupBy(PE => PE.Employee.Id)
                                   .Select(PE => new ProjectEmployeeDto
                {
                    EstWorkingHours = PE.Sum(a => a.EstWorkingHours),
                    EmployeeID = PE.First().EmployeeID,
                    Employee = PE.First().Employee,
                    ProjectId = PE.First().ProjectId
                }).ToList(),

                TotalAssignedHours = dto.ProjectEmployeeDtos.Sum(PE => (PE.Employee.Type.HourlyPrice + PE.Employee.Specialty.Bonus) * PE.EstWorkingHours),

                //working hours summed up by employee
                WorkingHours = dto.WorkingHoursDtos
                               .GroupBy(WH => WH.EmployeeId)
                               .Select(WH => new WorkingHoursDto
                {
                    Amount = WH.Sum(a => a.Amount),
                    EmployeeId = WH.First().EmployeeId,
                    Employee = WH.First().Employee,
                    ProjectId = WH.First().ProjectId,
                    HourlyPrice = WH.First().Employee.Type.HourlyPrice + WH.First().Employee.Specialty.Bonus
                }).ToList(),

                TotalUsedHours = dto.WorkingHoursDtos.Sum(WH => WH.Amount * WH.HourlyPrice),

                //assigned items summed up
                AssignedItems = dto.AssignedItemDtos.GroupBy(PAI => PAI.ItemID)
                                .Select(PAI => new ProjectAssignedItemDto
                {
                    Amount = PAI.Sum(c => c.Amount),
                    Item = PAI.First().Item,
                    Price = PAI.First().Price,
                    ProjectId = PAI.First().ProjectId
                }).ToList(),

                TotalAssignedItems = dto.AssignedItemDtos.Sum(UI => UI.Amount * UI.Price),

                //used items summed up
                UsedItems = dto.UsedItemsDtos.GroupBy(PUI => PUI.ItemID)
                            .Select(PUI => new ProjectUsedItemDto
                {
                    Amount = PUI.Sum(c => c.Amount),
                    Item = PUI.First().Item,
                    Price = PUI.First().Price,
                    ProjectId = PUI.First().ProjectId
                }).ToList(),
                TotalUsedItems = dto.UsedItemsDtos.Sum(UI => UI.Amount * UI.Price)
            });
        }