private List<JamScoreModel> TranslateRinxterScoringData(RinxterScoresModel rinxterModel) { List<JamScoreModel> modelList = new List<JamScoreModel>(); foreach(RinxterScoreRowModel row in rinxterModel.rows) { bool homeSP = row.data[3].ToString().Contains("*"); string[] homeScores = row.data[3].ToString().Split(' '); int homeJammerScore = 0; int homePivotScore = 0; int processLimit = homeScores.Length - 1; for(int i = 0; i < processLimit; i++) { if(homeScores[i].Contains("*")) { homeScores[i] = homeScores[i].Substring(0, homeScores[i].Length - 1); homePivotScore += Convert.ToInt16(homeScores[i]); } else { homeJammerScore += Convert.ToInt16(homeScores[i]); } } bool awaySP = row.data[8].ToString().Contains("*"); string[] awayScores = row.data[8].ToString().Split(' '); int awayJammerScore = 0; int awayPivotScore = 0; processLimit = awayScores.Length - 1; for (int i = 0; i < processLimit; i++) { if (awayScores[i].Contains("*")) { awayScores[i] = awayScores[i].Substring(0, awayScores[i].Length - 1); awayPivotScore += Convert.ToInt16(awayScores[i]); } else { awayJammerScore += Convert.ToInt16(awayScores[i]); } } JamScoreModel jamScoreModel = new JamScoreModel { IsFirstHalf = true, JamNumber = row.id + 1, AwayJammer = new ScoreModel { JamTotal = awayJammerScore, }, HomeJammer = new ScoreModel { JamTotal = homeJammerScore } }; if(homeSP) { jamScoreModel.HomeStarPass = new ScoreModel { JamTotal = homePivotScore }; } if(awaySP) { jamScoreModel.AwayStarPass = new ScoreModel { JamTotal = awayPivotScore }; } modelList.Add(jamScoreModel); } return modelList; }
private IList<JamScoreModel> ProcessScoreRows(ExcelRange homeScores, ExcelRange awayScores, bool isFirstHalf) { List<JamScoreModel> list = new List<JamScoreModel>(); int currentRow = 1; while (currentRow < 39) { object jamNumber = homeScores.SubRange(currentRow, 1).Value; if (jamNumber != null && !string.IsNullOrEmpty(jamNumber.ToString())) { if (jamNumber.ToString().Trim().ToLower() == "sp*") { currentRow++; continue; } // add jam int number = Convert.ToInt32(jamNumber); JamScoreModel model = new JamScoreModel(); model.JamNumber = number; model.IsFirstHalf = isFirstHalf; model.HomeJammer = CreateScoreModel(homeScores, currentRow); model.AwayJammer = CreateScoreModel(awayScores, currentRow); model.HomeStarPass = model.AwayStarPass = null; currentRow++; // see if the next home row is a star pass object nextJamNumber = homeScores.SubRange(currentRow, 1).Value; if (nextJamNumber != null && nextJamNumber.ToString().Trim().ToLower() == "sp" && homeScores.SubRange(currentRow, 2).Value != null && !string.IsNullOrWhiteSpace(homeScores.SubRange(currentRow, 2).Value.ToString())) { model.HomeStarPass = CreateScoreModel(homeScores, currentRow); } nextJamNumber = awayScores.SubRange(currentRow, 1).Value; if (nextJamNumber != null && nextJamNumber.ToString().Trim().ToLower() == "sp" && awayScores.SubRange(currentRow, 2).Value != null && !string.IsNullOrWhiteSpace(awayScores.SubRange(currentRow, 2).Value.ToString())) { model.AwayStarPass = CreateScoreModel(awayScores, currentRow); } if(model.AwayStarPass != null || model.HomeStarPass != null) { currentRow++; } list.Add(model); } else { break; } } return list; }