void RemoveTeam(object parameter) { lock (UndoActions) { var position = ((int[])parameter)[0]; var teamToDelete = Teams[position]; UndoActions.Add( new ChGKCommand { OnApply = () => { _service.RemoveTeam(teamToDelete.ID); _gaService.ReportEvent(GACategory.DealWithTeams, GAAction.Click, "team removed"); }, OnUndo = () => { Teams.Insert(position, teamToDelete); Teams = Teams.Where(_ => true).ToList(); }, }); Teams = Teams.Where((m, i) => i != position).ToList(); } UndoBarMetaData = new UndoBarMetadata { Text = StringResources.TeamRemoved }; }
private void AddPointToZone() { //if (_recognizer.State == UIGestureRecognizerState.Began) //{ // _dragStarted = false; // Console.WriteLine("Began !"); // return; //} //else if (_recognizer.State == UIGestureRecognizerState.Changed) //{ // _dragStarted = true; // Console.WriteLine("Drag !"); // // Do dragging stuff here //} //else if (_recognizer.State == UIGestureRecognizerState.Ended){ // if (_dragStarted) // { // Console.WriteLine("Ended 1!"); // _dragStarted = false; // return; // } // else { // Console.WriteLine("Ended !"); // } // } if (_recognizer.State == UIGestureRecognizerState.Began) { //if (_recognizer.State == UIGestureRecognizerState.Began || !IsOnPointAdding) return; if (ZonePolygon != null && ZonePolygon.Points.Count() > App.Locator.ModeZone.MAX_NUMBER_OF_POINTS) { return; } // convert touched position to map coordinate var userTouch = _recognizer.LocationInView(MapViewControl); var mapPoint = MapViewControl.ConvertPoint(userTouch, MapViewControl); var newAnnotation = new ModeZoneAnnotation(mapPoint, true); // change the previous annotation to green var lastAnnotation = PointsOfZone.LastOrDefault(); if (lastAnnotation != null) { MapViewControl.RemoveAnnotation(lastAnnotation); ((ModeZoneAnnotation)lastAnnotation).IsLastAnnotation = false; MapViewControl.AddAnnotation(lastAnnotation); } // refresh the polygone List <LatitudeLongitude> zone = PointsOfZone.Select(el => new LatitudeLongitude(el.Coordinate.Latitude, el.Coordinate.Longitude)).ToList(); zone.Add(new LatitudeLongitude(mapPoint.Latitude, mapPoint.Longitude)); if (!App.Locator.ModeZone.CheckCorrectAreaFormat(zone)) { return; } var pointsToRestore = PointsOfZone.Select(el => el.Coordinate).ToList(); PointsOfZone.Add(newAnnotation); MapViewControl.AddAnnotation(newAnnotation); var isInAlert = MapViewModelBase.Mode != null && MapViewModelBase.Mode.StatusDefinition_idstatusDefinition != 1; CreateZone(PointsOfZone.Select(s => new LatitudeLongitude(s.Coordinate.Latitude, s.Coordinate.Longitude)).ToList(), isInAlert, true, 0); RefreshZone(); // reverse the action UndoActions.Add(new Action(() => { MapViewControl.RemoveAnnotation(newAnnotation); PointsOfZone.Remove(PointsOfZone.Last()); var lastAnnotationUndo = PointsOfZone.LastOrDefault(); if (lastAnnotationUndo != null) { MapViewControl.RemoveAnnotation(lastAnnotationUndo); ((ModeZoneAnnotation)lastAnnotationUndo).IsLastAnnotation = true; MapViewControl.AddAnnotation(lastAnnotationUndo); } CreateZone(pointsToRestore.Select(s => new LatitudeLongitude(s.Latitude, s.Longitude)).ToList(), isInAlert, true, 0); RefreshZone(); if (ZonePolygon == null || ZonePolygon.Points == null || PointsOfZone.Count() < 3) { _nextButton.Enabled = false; } else { _nextButton.Enabled = true; } })); // if the zone contain 3 points, enable the next button if (PointsOfZone.Count < 3) { _nextButton.Enabled = false; } else { _nextButton.Enabled = true; } } }