public PrintModel FindOptimalPlacement() { var commertialPlacementsForProgram = new List <Placement[]>(); var commercialPermutationList = GetCommercialPermutations(); foreach (var Commercial in commercialPermutationList.ToList()) { commertialPlacementsForProgram.Add(_placement.BuildPlacements(Commercial.ToList())); } commertialPlacementsForProgram.RemoveAll(placements => placements.Any(p => p.Rate == 0)); commertialPlacementsForProgram.RemoveAll(placements => placements.Any(p => p.Commercional == null)); var optimalMaxRatePlacement = commertialPlacementsForProgram.ToList() .GroupBy(placements => placements.Sum(p => p.Rate)) .OrderByDescending(o => o.Key) .FirstOrDefault(); var printModel = new PrintModel(); foreach (var placements in optimalMaxRatePlacement) { printModel.Placements = placements; printModel.TotalRate = optimalMaxRatePlacement.Key; } ; return(printModel); }