New way to interact with AspNet users
This commit is contained in:
@@ -5,8 +5,5 @@ namespace Hutopy.Application.Common.Interfaces;
|
||||
public interface IApplicationDbContext
|
||||
{
|
||||
DbSet<FutureCreator> FutureCreators { get; }
|
||||
|
||||
DbSet<User> DomainUsers { get; }
|
||||
|
||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using System.Dynamic;
|
||||
using Hutopy.Application.Common.Interfaces;
|
||||
using Hutopy.Domain.Entities;
|
||||
using Hutopy.Domain.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Hutopy.Application.Users.Commands;
|
||||
public record CreateUserCommand : IRequest<Guid>
|
||||
@@ -14,26 +17,24 @@ public record CreateUserCommand : IRequest<Guid>
|
||||
public class CreateUserCommandHandler : IRequestHandler<CreateUserCommand, Guid>
|
||||
{
|
||||
private readonly IApplicationDbContext _context;
|
||||
private readonly IUserService _userService;
|
||||
|
||||
public CreateUserCommandHandler(IApplicationDbContext context)
|
||||
public CreateUserCommandHandler(IApplicationDbContext context, IUserService userService)
|
||||
{
|
||||
_context = context;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
public async Task<Guid> Handle(CreateUserCommand request, CancellationToken cancellationToken)
|
||||
{
|
||||
var entity = new User
|
||||
{
|
||||
FirstName = request.FirstName,
|
||||
LastName = request.LastName,
|
||||
EmailAddress = request.EmailAddress,
|
||||
UserName = request.UserName,
|
||||
};
|
||||
// Dont really need the handler for the create. The get will work like this :
|
||||
var user = await _userService.FindUserByIdAsync("a4baeb4f-e846-45c6-9be2-6655dd8d1baf");
|
||||
// var user2 = await _userService.FindUserByEmailAsync("test10@hotmail.com");
|
||||
|
||||
_context.DomainUsers.Add(entity);
|
||||
var tt = user?.UserName;
|
||||
|
||||
await _context.SaveChangesAsync(cancellationToken);
|
||||
|
||||
return entity.Id;
|
||||
return Guid.NewGuid();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user