2020-05-02 14:21:59 +02:00
|
|
|
|
using System.Linq;
|
2020-04-28 18:54:37 +02:00
|
|
|
|
using MediatR;
|
2020-03-26 12:25:22 +01:00
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Application.Group.Models;
|
|
|
|
|
using ModernKeePass.Domain.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Application.Group.Commands.SortGroups
|
|
|
|
|
{
|
|
|
|
|
public class SortGroupsCommand : IRequest
|
|
|
|
|
{
|
|
|
|
|
public GroupVm Group { get; set; }
|
|
|
|
|
|
2020-03-26 19:04:51 +01:00
|
|
|
|
public class SortGroupsCommandHandler : IRequestHandler<SortGroupsCommand>
|
2020-03-26 12:25:22 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly IDatabaseProxy _database;
|
|
|
|
|
|
2020-03-26 19:04:51 +01:00
|
|
|
|
public SortGroupsCommandHandler(IDatabaseProxy database)
|
2020-03-26 12:25:22 +01:00
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-26 19:04:51 +01:00
|
|
|
|
public void Handle(SortGroupsCommand message)
|
2020-03-26 12:25:22 +01:00
|
|
|
|
{
|
2020-03-26 19:04:51 +01:00
|
|
|
|
if (!_database.IsOpen) throw new DatabaseClosedException();
|
2020-03-26 12:25:22 +01:00
|
|
|
|
|
|
|
|
|
_database.SortSubGroups(message.Group.Id);
|
2020-04-28 18:54:37 +02:00
|
|
|
|
message.Group.SubGroups = message.Group.SubGroups.OrderBy(g => g.Title).ToList();
|
2020-03-26 12:25:22 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|