Ejemplo n.º 1
0
        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;
        }
Ejemplo n.º 2
0
        public void AddFileRecord(string fileUri)
        {
            IsRecordModified = false;
            var fileId = _fileIdGenerator.GetFileId();
            var fileRecordViewModel =
                new FileRecordViewModel(FileRecords, _fileSafe, Id, fileId, () => { IsRecordModified = true; })
            {
                Name        = Path.GetFileNameWithoutExtension(fileUri),
                Extention   = Path.GetExtension(fileUri)?.Replace(".", ""),
                Description = string.Empty,
            };

            FileRecords.Add(fileRecordViewModel);
            _fileSafe.StoreFile(Id, fileId, fileUri);
        }