private void SavePhilosopher() { if (ActiveRecord.IsChanged) { if (PhilVM.Controller.State == Controller.EditState.Edit) { var editPhil = Philosopher.CopyFrom(ActiveRecord); var prev = PhilVM.Philosophers.FirstOrDefault(p => p.Id == originalValue.Id); if (prev != null) { PhilVM.Philosophers.Remove(prev); } PhilVM.Philosophers.Add(editPhil); if (!string.IsNullOrEmpty(editPhil.LogoPath)) { var filePath = FileUtils.AppFolder.GetSubFolder("Images"); var file = new FileInfo(editPhil.LogoPath); var destFile = filePath.GetFile(file.Name); file.CopyMeTo(destFile); } else if (!string.IsNullOrEmpty(originalValue.LogoPath)) { var filePath = FileUtils.AppFolder.GetSubFolder("Images"); var file = new FileInfo(originalValue.LogoPath); var destFile = filePath.GetFile(file.Name); File.Delete(destFile.FullName); } } PhilVM.ListViewEnabled = true; } if (PhilVM.Controller.State == Controller.EditState.Add) { ButtonText = "Save"; PhilVM.Philosophers.Add(ActiveRecord); IsNewMode = false; } //if (PhilVM.Controller.State == Controller.EditState.Edit) //{ // PhilVM.Controller.SetState(Controller.EditState.View); //} IsNewMode = false; ButtonText = "Edit"; ButtonClickCommand = EditCommand; PhilVM.Controller.SetState(Controller.EditState.View); RaisePropertyChanged(nameof(CanRevert)); RaisePropertyChanged(nameof(CanSavePhilosopher)); }
private void EditPhilosopher() { PhilVM.Controller.State = Controller.EditState.Edit; originalValue = Philosopher.CopyFrom(ActiveRecord); ActiveRecord = Philosopher.CopyFrom(ActiveRecord); ActiveBook = (Philosopher.Books)(Philosopher.CopyFrom(ActiveBook)); ActiveRecord.Changed += SelectedPhilosopher_Changed; ButtonText = "Save"; ButtonClickCommand = SaveCommand; IsNewMode = true; }
private void OnRevert() { PhilVM.Controller.State = Controller.EditState.View; ActiveRecord = Philosopher.CopyFrom(originalValue); if (ActiveRecord != null) { ActiveRecord.Changed += SelectedPhilosopher_Changed; } if (PhilVM.Controller.State == Controller.EditState.View) { IsNewMode = false; PhilVM.ListViewEnabled = true; } }