create CreateUserCommand with handler and mapping profile
This commit is contained in:
parent
777f20eddb
commit
a7f6b94d20
@ -0,0 +1,105 @@
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using DigitalData.UserManager.Domain.Entities;
|
||||
using MediatR;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Users.Commands;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public record CreateUserCommand : IRequest<int>
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string? Prename { get; init; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string? Name { get; init; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public required string Username { get; init; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string? Shortname { get; init; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string? Email { get; init; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string Language { get; init; } = "de-DE";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string? Comment { get; init; }
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool Deleted { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string DateFormat { get; init; } = "dd.MM.yyyy";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool Active { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public string GeneralViewer { get; init; } = "NONE";
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public bool WanEnvironment { get; } = false;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public int UserIdFkIntEcm { get; init; } = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class CreateUserCommandHandler : IRequestHandler<CreateUserCommand, int>
|
||||
{
|
||||
private readonly IRepository<User> _repo;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="repo"></param>
|
||||
public CreateUserCommandHandler(IRepository<User> repo)
|
||||
{
|
||||
_repo = repo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <param name="cancel"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<int> Handle(CreateUserCommand request, CancellationToken cancel = default)
|
||||
{
|
||||
var user = await _repo.CreateAsync(request, cancel);
|
||||
return user.Id;
|
||||
}
|
||||
}
|
||||
19
EnvelopeGenerator.Application/Users/MappingProfile.cs
Normal file
19
EnvelopeGenerator.Application/Users/MappingProfile.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using AutoMapper;
|
||||
using DigitalData.UserManager.Domain.Entities;
|
||||
using EnvelopeGenerator.Application.Users.Commands;
|
||||
|
||||
namespace EnvelopeGenerator.Application.Users;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class MappingProfile : Profile
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public MappingProfile()
|
||||
{
|
||||
CreateMap<CreateUserCommand, User>();
|
||||
}
|
||||
}
|
||||
@ -54,6 +54,7 @@ public static class DIExtensions
|
||||
services.TryAddScoped<IReceiverRepository, ReceiverRepository>();
|
||||
services.TryAddScoped<IEnvelopeReceiverReadOnlyRepository, EnvelopeReceiverReadOnlyRepository>();
|
||||
|
||||
services.AddDbRepository<EGDbContext, User>(context => context.Users).UseAutoMapper();
|
||||
services.AddDbRepository<EGDbContext, Config>(context => context.Configs).UseAutoMapper();
|
||||
services.AddDbRepository<EGDbContext, DocumentReceiverElement>(context => context.DocumentReceiverElements).UseAutoMapper();
|
||||
services.AddDbRepository<EGDbContext, EnvelopeDocument>(context => context.EnvelopeDocument).UseAutoMapper();
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using Bogus;
|
||||
using Bogus.DataSets;
|
||||
using EnvelopeGenerator.Application;
|
||||
using EnvelopeGenerator.Application.Envelopes.Commands;
|
||||
using EnvelopeGenerator.Application.Receivers.Commands;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user