private MonthlyReportKindGameModel GetKindMonthlyReportModel(IGrouping <int, GameDto> gamesByKind) { var monthlyReportSubKindGameModels = new List <MonthlyReportSubKindGameModel>(); foreach (var subKind in gamesByKind.GroupBy(x => x.SubKind)) { if (subKind.Key.HasValue) { MonthlyReportSubKindGameModel subKindGameModel = GetSubKindMonthlyReportModel(gamesByKind.Key, subKind); monthlyReportSubKindGameModels.Add(subKindGameModel); } } var monthlyReportKindGameModel = new MonthlyReportKindGameModel { Kind = gamesByKind.Key, KindName = GamesByType.FirstOrDefault(x => x.Kind == gamesByKind.Key).KindName, MonthlyReportSubKindGameModels = monthlyReportSubKindGameModels }; List <int> gameIds = GamesByType.Where(x => x.Kind == gamesByKind.Key).Select(x => x.Id).ToList(); monthlyReportKindGameModel = SetPlans(monthlyReportKindGameModel, gameIds); return(monthlyReportKindGameModel); }
private MonthlyReportSubKindGameModel GetSubKindMonthlyReportModel(int?gameKind, IGrouping <int?, GameDto> gamesBySubKind) { if (!gamesBySubKind.Key.HasValue) { return(new MonthlyReportSubKindGameModel()); } List <GameHuntPlanDto> classHuntPlans = (from game in GamesByType join huntPlan in HuntPlans on game.Id equals huntPlan.GameId where game.Kind == gameKind && game.SubKind == gamesBySubKind.Key && huntPlan.Class != null select huntPlan).ToList(); var monthlyReportClassGameModels = new List <MonthlyReportClassGameModel>(); foreach (GameHuntPlanDto classHuntPlan in classHuntPlans) { MonthlyReportClassGameModel monthlyReportClassGameModel = GetClassMonthlyReportModel(classHuntPlan); monthlyReportClassGameModels.Add(monthlyReportClassGameModel); } var monthlyReportSubKindGameModel = new MonthlyReportSubKindGameModel { SubKind = gamesBySubKind.Key, SubKindName = GamesByType.FirstOrDefault(x => x.Kind == gameKind && x.SubKind == gamesBySubKind.Key).SubKindName, MonthlyReportClassGameModels = monthlyReportClassGameModels }; int gameId = GamesByType.FirstOrDefault(x => x.Kind == gameKind && x.SubKind == gamesBySubKind.Key).Id; monthlyReportSubKindGameModel = SetPlans(monthlyReportSubKindGameModel, new List <int> { gameId }); return(monthlyReportSubKindGameModel); }