public RecordViewModel(Record record, IFileSafe fileSafe, IFileIdGenerator fileIdGenerator) { _fileSafe = fileSafe; _fileIdGenerator = fileIdGenerator; Id = record.Header.Id; Name = record.Header.Name; Tags = record.Header.Tags; PasswordRecords = new ObservableCollection <PasswordRecordViewModel>(); FileRecords = new ObservableCollection <FileRecordViewModel>(); PasswordRecords.CollectionChanged += (sender, args) => { IsRecordModified = true; }; FileRecords.CollectionChanged += (sender, args) => { IsRecordModified = true; }; foreach (var passwordRecord in record.PasswordRecords) { AddNewPasswordRecord(passwordRecord.Name, passwordRecord.Value); } foreach (var fileRecord in record.FileRecords) { var fileRecordViewModel = new FileRecordViewModel(FileRecords, _fileSafe, fileRecord.AssociatedRecordId, fileRecord.FileId, () => { IsRecordModified = true; }) { Name = fileRecord.Name, Description = fileRecord.Description, Extention = fileRecord.Extention }; FileRecords.Add(fileRecordViewModel); } _initialized = true; AddNewPasswordRecord(string.Empty, string.Empty); IsRecordModified = false; }
public FileRecordViewModel(ObservableCollection <FileRecordViewModel> fileRecordViewModels, IFileSafe safe, string recordId, string fileId, Action onChangeAction) { _safe = safe; _onChangeAction = onChangeAction; RecordId = recordId; FileRecordId = fileId; DeleteCommand = new DelegateCommand(() => fileRecordViewModels.Remove(this)); }
public void SetUp() { _id = "someId"; _name = "someName"; _tagString = "tag1;tag2"; _passwordRecords = new List <PasswordRecord>() { new PasswordRecord() { Name = "Name1", Value = "Value1" }, new PasswordRecord() { Name = "Name2", Value = "Value2" }, new PasswordRecord() { Name = "Name3", Value = "Value3" }, }; _fileRecords = new List <FileRecord>() { new FileRecord() { Name = "Name1", Extention = "pdf", Description = "Description1", AssociatedRecordId = _id, FileId = "F1" }, new FileRecord() { Name = "Name2", Extention = "txt", Description = "Description2", AssociatedRecordId = _id, FileId = "F2" }, new FileRecord() { Name = "Name3", Extention = "xlsx", Description = "Description3", AssociatedRecordId = _id, FileId = "F3" }, }; var record = new Record { Header = new RecordHeader(), FileRecords = new List <FileRecord>(), PasswordRecords = new List <PasswordRecord>() }; record.Header.Id = _id; record.Header.Name = _name; record.Header.Tags = _tagString; record.PasswordRecords.AddRange(_passwordRecords); record.FileRecords.AddRange(_fileRecords); _fileSafe = Substitute.For <IFileSafe>(); _fileIdGenerator = Substitute.For <IFileIdGenerator>(); _recordViewModel = new RecordViewModel(record, _fileSafe, _fileIdGenerator); _recordModificationStatus = false; _recordViewModel.RecordChanged += () => { _recordModificationStatus = _recordViewModel.IsRecordModified; }; }