Lots of bug corrections

WIP - still lots left
This commit is contained in:
Geoffroy BONNEVILLE
2020-03-31 19:19:02 +02:00
parent e4bd788ed3
commit 90c592d7ee
24 changed files with 191 additions and 215 deletions

View File

@@ -1,9 +1,12 @@
using System.Threading.Tasks;
using System.Linq;
using System.Threading.Tasks;
using AutoMapper;
using MediatR;
using ModernKeePass.Application.Common.Interfaces;
using ModernKeePass.Application.Entry.Models;
using ModernKeePass.Application.Group.Models;
using ModernKeePass.Domain.Dtos;
using ModernKeePass.Domain.Entities;
using ModernKeePass.Domain.Exceptions;
namespace ModernKeePass.Application.Database.Queries.OpenDatabase
@@ -39,7 +42,29 @@ namespace ModernKeePass.Application.Database.Queries.OpenDatabase
KeyFilePath = request.KeyFilePath,
Password = request.Password
});
return _mapper.Map<GroupVm>(rootGroup);
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;
}
}
}