//A custom made Equals method to handle the List operations public override bool Equals(object obj) { if (obj == null) { return(false); } //Convert the input into both a ViewModelPlot and a Plot ViewModelPlot objAsViewModelPlot = obj as ViewModelPlot; Plot objAsPlot = obj as Plot; //Validate objasViewModelPlot and then check the trackID and thetime in order to identify the plot if (objAsViewModelPlot != null) { if ((objAsViewModelPlot.trackID == this.trackID) && (objAsViewModelPlot.time == this.time)) { return(true); } } //Validate objAsPlot and then check the trackID and thetime in order to identify the plot if (objAsPlot != null) { if ((objAsPlot.trackID == this.trackID) && (objAsPlot.time == this.time)) { return(true); } } //If both checks fail - return false return(false); }
/* * Edit a plot * * -validate the input * -find the trackToLookInto * -validate the trackToLookInto * -find the plotToBeChanged * -validate the plotToBeChanged * -edit the plot * */ private void handleEditPlot(Plot p) { if (p != null) { ViewModelTrack trackToLookInto = tracks.First(x => x.trackID == p.trackID); if (trackToLookInto != null) { ViewModelPlot plotToBeChanged = trackToLookInto.plots.First(x => x.Equals(new ViewModelPlot(p))); if (plotToBeChanged != null) { plotToBeChanged.edit(p); } } } }
/* Create a new plot * * -validate the input * -find the trackToAddTo * -validate the trackToAddTo * -convert the input to a ViewModelPlot * -add the plot * -select the plot * */ private void handleCreatePlot(Plot p) { if (p != null) { var trackToAddInto = tracks.First(x => x.trackID == p.trackID); if (trackToAddInto != null) { ViewModelPlot vmPlot = new ViewModelPlot(p); trackToAddInto.plots.Add(vmPlot); //check if the plot being created belongs tot he track selected if (selectedTrack != null) { if (selectedTrack.trackID == vmPlot.trackID) { selectedPlot = vmPlot; } } } } }