mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Build hierarchy instead of using Automapper
Add entities before removing them
This commit is contained in:
@@ -39,7 +39,7 @@ namespace ModernKeePass.Application.Database.Commands.CreateDatabase
|
||||
KeyFilePath = message.KeyFilePath,
|
||||
Password = message.Password
|
||||
});
|
||||
return _mapper.Map<GroupVm>(rootGroup);
|
||||
return GroupVm.BuildHierarchy(null, rootGroup, _mapper);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -28,7 +28,7 @@ namespace ModernKeePass.Application.Database.Queries.GetDatabase
|
||||
if (database.IsOpen)
|
||||
{
|
||||
database.Name = _databaseProxy.Name;
|
||||
database.RootGroup = _mapper.Map<GroupVm>(_databaseProxy.RootGroup);
|
||||
database.RootGroup = GroupVm.BuildHierarchy(null, _databaseProxy.RootGroup, _mapper);
|
||||
database.IsRecycleBinEnabled = _databaseProxy.IsRecycleBinEnabled;
|
||||
database.RecycleBin = _mapper.Map<GroupVm>(_databaseProxy.RecycleBin);
|
||||
database.Compression = _databaseProxy.Compression;
|
||||
|
@@ -42,30 +42,9 @@ namespace ModernKeePass.Application.Database.Queries.OpenDatabase
|
||||
KeyFilePath = request.KeyFilePath,
|
||||
Password = request.Password
|
||||
});
|
||||
return BuildHierarchy(null, rootGroup);
|
||||
}
|
||||
|
||||
private GroupVm BuildHierarchy(GroupVm parentGroup, GroupEntity groupEntity)
|
||||
{
|
||||
var groupVm = _mapper.Map<GroupVm>(groupEntity);
|
||||
groupVm.ParentGroup = parentGroup;
|
||||
if (parentGroup != null)
|
||||
{
|
||||
groupVm.Breadcrumb.AddRange(parentGroup.Breadcrumb);
|
||||
groupVm.Breadcrumb.Add(parentGroup);
|
||||
}
|
||||
groupVm.Entries = groupEntity.Entries.Select(e =>
|
||||
{
|
||||
var entry = _mapper.Map<EntryVm>(e);
|
||||
entry.ParentGroup = groupVm;
|
||||
entry.Breadcrumb.AddRange(groupVm.Breadcrumb);
|
||||
entry.Breadcrumb.Add(groupVm);
|
||||
return entry;
|
||||
}).OrderBy(e => e.Title).ToList();
|
||||
groupVm.SubGroups = groupEntity.SubGroups.Select(g => BuildHierarchy(groupVm, g)).ToList();
|
||||
|
||||
return groupVm;
|
||||
return GroupVm.BuildHierarchy(null, rootGroup, _mapper);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@@ -25,7 +25,7 @@ namespace ModernKeePass.Application.Database.Queries.ReOpenDatabase
|
||||
if (!_database.IsOpen) throw new DatabaseClosedException();
|
||||
|
||||
var rootGroup = await _database.ReOpen();
|
||||
return _mapper.Map<GroupVm>(rootGroup);
|
||||
return GroupVm.BuildHierarchy(null, rootGroup, _mapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -37,7 +37,7 @@ namespace ModernKeePass.Application.Entry.Models
|
||||
public void Mapping(Profile profile)
|
||||
{
|
||||
profile.CreateMap<EntryEntity, EntryVm>()
|
||||
//.ForMember(d => d.ParentGroup, opts => opts.MapFrom(s => s.Parent))
|
||||
.ForMember(d => d.ParentGroup, opts => opts.Ignore())
|
||||
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
|
||||
.ForMember(d => d.Title, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.Username, opts => opts.MapFrom(s => s.UserName))
|
||||
|
@@ -29,6 +29,7 @@ namespace ModernKeePass.Application.Group.Commands.CreateGroup
|
||||
|
||||
var group = _database.CreateGroup(message.ParentGroup.Id, message.Name, message.IsRecycleBin);
|
||||
var groupVm = _mapper.Map<GroupVm>(group);
|
||||
groupVm.ParentGroup = message.ParentGroup;
|
||||
message.ParentGroup.SubGroups.Add(groupVm);
|
||||
return groupVm;
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using AutoMapper;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
@@ -29,13 +30,34 @@ namespace ModernKeePass.Application.Group.Models
|
||||
public void Mapping(Profile profile)
|
||||
{
|
||||
profile.CreateMap<GroupEntity, GroupVm>()
|
||||
//.ForMember(d => d.ParentGroup, opts => opts.MapFrom(s => s.Parent))
|
||||
.ForMember(d => d.ParentGroup, opts => opts.Ignore())
|
||||
.ForMember(d => d.Id, opts => opts.MapFrom(s => s.Id))
|
||||
.ForMember(d => d.Title, opts => opts.MapFrom(s => s.Name))
|
||||
.ForMember(d => d.Icon, opts => opts.MapFrom(s => s.Icon));
|
||||
//.ForMember(d => d.Entries, opts => opts.MapFrom(s => s.Entries.OrderBy(e => e.Name)))
|
||||
//.ForMember(d => d.SubGroups, opts => opts.MapFrom(s => s.SubGroups));
|
||||
.ForMember(d => d.Icon, opts => opts.MapFrom(s => s.Icon))
|
||||
.ForMember(d => d.Entries, opts => opts.Ignore())
|
||||
.ForMember(d => d.SubGroups, opts => opts.Ignore());
|
||||
}
|
||||
|
||||
internal static GroupVm BuildHierarchy(GroupVm parentGroup, GroupEntity groupEntity, IMapper mapper)
|
||||
{
|
||||
var groupVm = mapper.Map<GroupVm>(groupEntity);
|
||||
groupVm.ParentGroup = parentGroup;
|
||||
if (parentGroup != null)
|
||||
{
|
||||
groupVm.Breadcrumb.AddRange(parentGroup.Breadcrumb);
|
||||
groupVm.Breadcrumb.Add(parentGroup);
|
||||
}
|
||||
groupVm.Entries = groupEntity.Entries.Select(e =>
|
||||
{
|
||||
var entry = mapper.Map<EntryVm>(e);
|
||||
entry.ParentGroup = groupVm;
|
||||
entry.Breadcrumb.AddRange(groupVm.Breadcrumb);
|
||||
entry.Breadcrumb.Add(groupVm);
|
||||
return entry;
|
||||
}).OrderBy(e => e.Title).ToList();
|
||||
groupVm.SubGroups = groupEntity.SubGroups.Select(g => BuildHierarchy(groupVm, g, mapper)).ToList();
|
||||
|
||||
return groupVm;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user