예제 #1
0
        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));
        }
예제 #2
0
        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;
        }
예제 #3
0
 private void AddPhilosopher()
 {
     ListViewEnabled        = false;
     EditControls.IsNewMode = true;
     Controller.State       = Controller.EditState.Add;
     SelectedPhilosopher    = new Philosopher();
     if (Controller.State == Controller.EditState.Add)
     {
         EditControls.ButtonText            = "Save";
         EditControls.ButtonClickCommand    = EditControls.SaveCommand;
         EditControls.ActiveRecord.Changed += SelectedPhilosopher_Changed;
     }
     //IsNewMode = true;
 }
예제 #4
0
        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;
            }
        }
예제 #5
0
        public static Philosopher CopyFrom(Philosopher philosopher)
        {
            if (philosopher == null)
            {
                return(null);
            }

            return(new Philosopher()
            {
                Id = philosopher.Id,
                LogoPath = philosopher.LogoPath,
                Name = philosopher.Name,
                Subject = philosopher.Subject,
                Era = philosopher.Era,
                Influential = philosopher.Influential,
                IsChanged = false,
                Book = philosopher.Book
            });
        }