/// <summary> /// Adjusts the handicap. /// </summary> /// <param name="handicapAdjustmentDataTransferObject">The handicap adjustment data transfer object.</param> /// <param name="tournamentId">The tournament identifier.</param> /// <param name="golfClubId">The golf club identifier.</param> /// <param name="measuredCourseId">The measured course identifier.</param> /// <param name="scoreDate">The score date.</param> public void AdjustHandicap(HandicapAdjustmentDataTransferObject handicapAdjustmentDataTransferObject, Guid tournamentId, Guid golfClubId, Guid measuredCourseId, DateTime scoreDate) { Guard.ThrowIfNull(handicapAdjustmentDataTransferObject, typeof(ArgumentNullException), "Handicap Adjustment details must be provided to adjust a players handicap"); Guard.ThrowIfInvalidGuid(tournamentId, typeof(ArgumentNullException), "Tournament Id must be provided to adjust a players handicap"); Guard.ThrowIfInvalidGuid(golfClubId, typeof(ArgumentNullException), "Golf Club Id must be provided to adjust a players handicap"); Guard.ThrowIfInvalidGuid(measuredCourseId, typeof(ArgumentNullException), "Measured Course Id must be provided to adjust a players handicap"); Guard.ThrowIfInvalidDate(scoreDate, typeof(ArgumentNullException), "Score Date must be provided to adjust a players handicap"); this.CheckIfPlayerHasBeenRegistered(); this.CheckNotDuplicateHandicapAdjustment(handicapAdjustmentDataTransferObject, tournamentId, golfClubId, measuredCourseId, scoreDate); HandicapAdjustedEvent handicapAdjustedEvent = HandicapAdjustedEvent.Create(this.AggregateId, handicapAdjustmentDataTransferObject.NumberOfStrokesBelowCss, handicapAdjustmentDataTransferObject.AdjustmentValuePerStroke, handicapAdjustmentDataTransferObject.TotalAdjustment, tournamentId, golfClubId, measuredCourseId, scoreDate); this.ApplyAndPend(handicapAdjustedEvent); }
/// <summary> /// /// </summary> /// <param name="handicapAdjustmentDataTransferObject"></param> /// <param name="tournamentId"></param> /// <param name="golfClubId"></param> /// <param name="measuredCourseId"></param> /// <param name="scoreDate"></param> private void CheckNotDuplicateHandicapAdjustment(HandicapAdjustmentDataTransferObject handicapAdjustmentDataTransferObject, Guid tournamentId, Guid golfClubId, Guid measuredCourseId, DateTime scoreDate) { if (this.HandicapAdjustments.Any(h => h.GolfClubId == golfClubId && h.AdjustmentValuePerStroke == handicapAdjustmentDataTransferObject.AdjustmentValuePerStroke && h.MeasuredCourseId == measuredCourseId && h.NumberOfStrokesBelowCss == handicapAdjustmentDataTransferObject.NumberOfStrokesBelowCss && h.TournamentId == tournamentId && h.ScoreDate == scoreDate && h.TotalAdjustment == handicapAdjustmentDataTransferObject.TotalAdjustment)) { throw new InvalidOperationException("Handicap adjustment has already been applied to this player"); } }