private void EditTrain(string trainId) { Log.Trace(CultureInfo.CurrentCulture, Resources.LogMessage_EnteringEditTrain, trainId); if (!Model.TrainList.Any(t => t.Id == trainId)) { Log.Warn(CultureInfo.CurrentCulture, Resources.LogWarning_TrainDoesNotExist, trainId); return; } Train targetTrain = Model.TrainList.First(t => t.Id == trainId); Train copyTrain = targetTrain.Copy(); copyTrain.Id = GeneralHelper.GetNewId(Model.TrainList); TrainEditFormModel formModel = GetBaseTrainEditFormModel(); formModel.Data = copyTrain; using (TrainEditForm tef = new TrainEditForm { Model = formModel }) { DialogResult result = tef.ShowDialog(); Log.Trace("TrainEditForm.ShowDialog() returned {0}", result); if (result != DialogResult.OK) { return; } Model.TrainList.Remove(targetTrain); Model.TrainList.Add(tef.Model.Data); } }
private void AddTrain() { TrainEditFormModel formModel = GetBaseTrainEditFormModel(); formModel.Data = new Train { Id = GeneralHelper.GetNewId(Model.TrainList) }; using (TrainEditForm form = new TrainEditForm { Model = formModel }) { DialogResult result = form.ShowDialog(); Log.Trace("TrainEditForm.ShowDialog() returned {0}", result); if (result != DialogResult.OK) { return; } if (form.Model != null && form.Model.Data != null) { Model.TrainList.Add(form.Model.Data); } } }