2020-03-26 19:04:51 +01:00
|
|
|
|
using AutoMapper;
|
2020-03-26 12:25:22 +01:00
|
|
|
|
using MediatR;
|
|
|
|
|
using ModernKeePass.Application.Common.Interfaces;
|
|
|
|
|
using ModernKeePass.Application.Group.Models;
|
|
|
|
|
using ModernKeePass.Domain.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.Application.Group.Commands.CreateGroup
|
|
|
|
|
{
|
|
|
|
|
public class CreateGroupCommand : IRequest<GroupVm>
|
|
|
|
|
{
|
2020-04-01 19:37:30 +02:00
|
|
|
|
public string ParentGroupId { get; set; }
|
2020-03-26 12:25:22 +01:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public bool IsRecycleBin { get; set; }
|
|
|
|
|
|
2020-03-26 19:04:51 +01:00
|
|
|
|
public class CreateGroupCommandHandler : IRequestHandler<CreateGroupCommand, GroupVm>
|
2020-03-26 12:25:22 +01:00
|
|
|
|
{
|
|
|
|
|
private readonly IDatabaseProxy _database;
|
|
|
|
|
private readonly IMapper _mapper;
|
|
|
|
|
|
2020-03-26 19:04:51 +01:00
|
|
|
|
public CreateGroupCommandHandler(IDatabaseProxy database, IMapper mapper)
|
2020-03-26 12:25:22 +01:00
|
|
|
|
{
|
|
|
|
|
_database = database;
|
|
|
|
|
_mapper = mapper;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-26 19:04:51 +01:00
|
|
|
|
public GroupVm Handle(CreateGroupCommand 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
|
|
|
|
|
2020-04-01 19:37:30 +02:00
|
|
|
|
var group = _database.CreateGroup(message.ParentGroupId, message.Name, message.IsRecycleBin);
|
2020-03-26 12:25:22 +01:00
|
|
|
|
var groupVm = _mapper.Map<GroupVm>(group);
|
|
|
|
|
return groupVm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|