示例#1
0
        public AddOperationViewModel(Action discardAction, Action <string> saveAction, IRecordIdGenerator recordIdGenerator, IFileIdGenerator fileIdGenerator, ISafe safe)
        {
            Record = new RecordViewModel(CreateEmptyRecord(recordIdGenerator.GetRecordId()), safe, fileIdGenerator);
            Record.PropertyChanged += (sender, args) =>
            {
                CanExecuteSaveCommand = !string.IsNullOrWhiteSpace(Record.Name);
            };

            DiscardCommand = new DelegateCommand
                                 (() =>
            {
                safe.ReorganizeFiles(Record.Id);
                discardAction.Invoke();
            }
                                 );

            SaveCommand = new DelegateCommand(() =>
            {
                var record = Record.GetRecord();
                safe.UpsertRecord(record);
                safe.ReorganizeFiles(Record.Id);
                saveAction.Invoke(Record.Id);
            }, () => CanExecuteSaveCommand);
        }