private void OnCancel() { if (AddMode) { ShutdownModelCollection.Remove(SelectedModel); SelectedModel = null; AddMode = false; } else if (EditMode) { EditMode = false; SelectedModel.CancelEdit(); } else if (RemoveMode) { foreach (var item in ShutdownModelCollection) { if (item.IsChecked) { item.IsChecked = false; } } RemoveMode = false; } CanUseDatagrid = true; CanEditFields = false; }
private async void AddEditRemoveOperation(string mode) { try { bool success = true; string error = ""; OnInfoRequested("Loading..."); await Task.Run(() => { try { List <ShutdownModel> list; if (ShutdownModelCollection.Count > 0) { list = ShutdownModelCollection.Select(x => ShutdownModelConverter.ConvertFrom(x)).ToList(); } else { list = new List <ShutdownModel>(); } var result = IOSerializeDeserialize.Serialize(list); if (!result.Success) { success = false; error = result.ErrorMessage; } else { result = Controller.RefreshService(); if (!result.Success) { success = false; error = $"Data {mode} successfully. But, service generated error. {result.ErrorMessage}"; } } } catch (Exception ex) { success = false; error = $"An error occured. {ex.Message}"; } }); if (success) { OnInfoRequested($"Data {mode} successfully"); if (mode == "edited") { SelectedModel.EndEdit(); } } else { OnErrorOccured(error); if (mode == "edited") { SelectedModel.CancelEdit(); } } } catch (Exception ex) { OnErrorOccured(ex.Message); } }