private void HandleNewTyreSelection(TyrePlacementViewModel tyrePlacementWithNewSelectedTyre) { if (tyrePlacementWithNewSelectedTyre.SelectedTyre == null) { // Nothing to validate return; } /* Validation rules are as follows: * • All four tyres should be of the same type (i.e. SuperSoft) * • Only tyres of the same Family should be placed on the same axle (e.g. if Front Left tyre Family = ‘F1’ then Front Right tyre must also have Family = ‘F1’. * Rear tyres must be of the same Family but this can be different to the Front tyres, for example, ‘F5’) * • Incompatible tyre selection(s) should be unselected when a new selection is made that breaks either of the above rules. */ var doesNewSelectionMatchFamilyOnAxle = IsNewTyreOnSameAxleSameFamily(tyrePlacementWithNewSelectedTyre); if (!doesNewSelectionMatchFamilyOnAxle) { ClearIncompatibleTyreFamilyOnSameAxle(tyrePlacementWithNewSelectedTyre); } var isNewSelectionSameTypeAsOthers = IsNewTyreSameTypeAsOthers(tyrePlacementWithNewSelectedTyre); if (!isNewSelectionSameTypeAsOthers) { ClearIncompatibleTyreTypeSelections(tyrePlacementWithNewSelectedTyre); } UpdateResults(); }
private void ClearIncompatibleTyreTypeSelections(TyrePlacementViewModel tyrePlacementWithNewSelectedTyre) { var placementsToClear = AllTyrePlacements.Where(p => p.SelectedTyre != null && p != tyrePlacementWithNewSelectedTyre); foreach (var placement in placementsToClear) { VoidPlacement(placement); } }
public CurrentSelectionViewModel(IHasTyresList <TyreDetailsViewModel> hasTyresDetailsList, IWeatherService weatherService) { hasTyresDetailsList.TyresListUpdated += TyresListUpdated_UpdateAllowedTyres; _weatherService = weatherService; FrontLeft = new TyrePlacementViewModel(TyrePlacement.FL); FrontRight = new TyrePlacementViewModel(TyrePlacement.FR); RearLeft = new TyrePlacementViewModel(TyrePlacement.RL); RearRight = new TyrePlacementViewModel(TyrePlacement.RR); AllTyrePlacements = new[] { FrontLeft, FrontRight, RearLeft, RearRight }; foreach (var tyrePlacement in AllTyrePlacements) { tyrePlacement.SelectedTyreChanged += TyrePlacement_SelectedTyreChanged; } }
internal bool IsNewTyreSameTypeAsOthers(TyrePlacementViewModel tyrePlacementWithNewSelectedTyre) { var placementsWithSelectedTyres = AllTyrePlacements.Where(t => t.SelectedTyre != null); return(placementsWithSelectedTyres.All(t => t.SelectedTyre.Type == tyrePlacementWithNewSelectedTyre.SelectedTyre.Type)); }
internal TyrePlacementViewModel GetTyrePlacementOnSameAxleAs(TyrePlacementViewModel tyrePlacementViewModel) { return(AllTyrePlacements.FirstOrDefault(tyre => tyre != tyrePlacementViewModel && tyre.Axle == tyrePlacementViewModel.Axle)); }
internal bool IsNewTyreOnSameAxleSameFamily(TyrePlacementViewModel tyrePlacementWithNewSelectedTyre) { var tyreOnSameAxle = GetTyrePlacementOnSameAxleAs(tyrePlacementWithNewSelectedTyre); return(tyreOnSameAxle?.SelectedTyre == null || tyrePlacementWithNewSelectedTyre.SelectedTyre.IsSameFamilyAs(tyreOnSameAxle.SelectedTyre)); }
private void VoidPlacement(TyrePlacementViewModel placement) { placement.SelectedTyre = null; placement.IsValid = false; }
private void ClearIncompatibleTyreFamilyOnSameAxle(TyrePlacementViewModel tyrePlacementWithNewSelectedTyre) { var tyreOnSameAxle = GetTyrePlacementOnSameAxleAs(tyrePlacementWithNewSelectedTyre); VoidPlacement(tyreOnSameAxle); }