public ActionResult UpdateMatchResults(MatchResultUpdateModel[] updates) { var manager = ServiceProvider.Get<ICompetitionsManager>(); UpdateStartTimes(updates, manager); UpdateScores(updates, manager); return new HttpStatusCodeResult(200); }
private void UpdateStartTimes(MatchResultUpdateModel[] updates, ICompetitionsManager manager) { var dateUpdates = updates.Where( up => (up.StartTimeHours.HasValue || up.StartTimeMinutes.HasValue || up.StartTimeType.HasValue) && up.Date.NotNullOrEmpty()); var startTimeUpdates = dateUpdates.Select( dateUpdate => { var startTimeUpdateInfo = new MatchStartTimeUpdateInfo(); startTimeUpdateInfo.MatchId = dateUpdate.Id; startTimeUpdateInfo.StartTime = BuildStartTime(dateUpdate.Date, dateUpdate.StartTimeHours, dateUpdate.StartTimeMinutes); if (dateUpdate.StartTimeType.HasValue) { startTimeUpdateInfo.StartTimeType = dateUpdate.StartTimeType.Value; } return startTimeUpdateInfo; }); manager.UpdateMatchStartTime(startTimeUpdates.ToArray()); }
private void UpdateScores(MatchResultUpdateModel[] updates, ICompetitionsManager manager) { var matchScoreUpdateInfoItems = new List<MatchScoreUpdateInfo>(); updates.ForEach(update => { var matchScoreUpdateInfo = new MatchScoreUpdateInfo(); matchScoreUpdateInfo.MatchId = update.Id; matchScoreUpdateInfo.Result = update.Result; matchScoreUpdateInfo.Winner = update.Winner; matchScoreUpdateInfoItems.Add(matchScoreUpdateInfo); if (update.SetScores.NotNullOrEmpty()) { var scores = update.SetScores.Where(s => !(s.Player1Points == 0 && s.Player2Points == 0)); if (scores.NotNullOrEmpty()) { matchScoreUpdateInfo.SetScores = update.SetScores; } } }); if (matchScoreUpdateInfoItems.NotNullOrEmpty()) { manager.UpdateMatchScore(matchScoreUpdateInfoItems.ToArray()); } }