public async Task UpdateEntry(string entryId, string fieldName, object fieldValue, bool isProtected) { var pwEntry = _pwDatabase.RootGroup.FindEntry(BuildIdFromString(entryId), true); switch (fieldName) { case EntryFieldName.HasExpirationDate: pwEntry.Expires = (bool)fieldValue; break; case EntryFieldName.ExpirationDate: pwEntry.ExpiryTime = (DateTime)fieldValue; break; case EntryFieldName.Icon: pwEntry.IconId = IconMapper.MapIconToPwIcon((Icon)fieldValue); break; case EntryFieldName.BackgroundColor: pwEntry.BackgroundColor = (Color)fieldValue; break; case EntryFieldName.ForegroundColor: pwEntry.ForegroundColor = (Color)fieldValue; break; default: var stringValue = fieldValue == null ? string.Empty: fieldValue.ToString(); var unprotectedFieldValue = isProtected ? await _cryptography.UnProtect(stringValue) : stringValue; pwEntry.Strings.Set(fieldName, new ProtectedString(isProtected, unprotectedFieldValue)); break; } }
public void UpdateGroup(GroupEntity group) { var pwGroup = _pwDatabase.RootGroup.FindGroup(BuildIdFromString(group.Id), true); pwGroup.Name = group.Name; pwGroup.IconId = IconMapper.MapIconToPwIcon(group.Icon); pwGroup.Touch(true); }
public MappingProfiles() { CreateMap <KeyValuePair <string, ProtectedString>, FieldEntity>() .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Key)) .ForMember(dest => dest.Value, opt => opt.ResolveUsing <ProtectedStringResolver>()) .ForMember(dest => dest.IsProtected, opt => opt.MapFrom(src => src.Value.IsProtected)); CreateMap <PwEntry, EntryEntity>() .ForMember(dest => dest.ParentGroupId, opt => opt.MapFrom(src => src.ParentGroup.Uuid.ToHexString())) .ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Uuid.ToHexString())) .ForMember(dest => dest.Fields, opt => opt.MapFrom(src => src.Strings)) .ForMember(dest => dest.ExpirationDate, opt => opt.MapFrom(src => new DateTimeOffset(src.ExpiryTime))) .ForMember(dest => dest.HasExpirationDate, opt => opt.MapFrom(src => src.Expires)) .ForMember(dest => dest.Icon, opt => opt.MapFrom(src => IconMapper.MapPwIconToIcon(src.IconId))) .ForMember(dest => dest.ModificationDate, opt => opt.MapFrom(src => new DateTimeOffset(src.LastModificationTime))) .ForMember(dest => dest.Attachments, opt => opt.MapFrom(src => src.Binaries.Select(b => new KeyValuePair <string, byte[]> (b.Key, b.Value.ReadData())))); CreateMap <PwGroup, GroupEntity>() .ForMember(d => d.ParentGroupId, opts => opts.MapFrom(s => s.ParentGroup.Uuid.ToHexString())) .ForMember(d => d.Id, opts => opts.MapFrom(s => s.Uuid.ToHexString())) .ForMember(d => d.Icon, opts => opts.MapFrom(s => IconMapper.MapPwIconToIcon(s.IconId))) .ForMember(d => d.ModificationDate, opts => opts.MapFrom(s => s.LastModificationTime)) .MaxDepth(2); }