New way to interact with AspNet users

This commit is contained in:
Dominic Villemure
2024-04-09 23:38:26 -04:00
parent 47121b0539
commit 49a10198e4
13 changed files with 476 additions and 77 deletions

View File

@@ -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);
}

View File

@@ -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();
}
}
}