This repository has been archived by the owner on Jul 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
backend/src/Logitar.Master.Application/Accounts/Events/UserSignedInEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using Logitar.Portal.Contracts.Sessions; | ||
using MediatR; | ||
|
||
namespace Logitar.Master.Application.Accounts.Events; | ||
|
||
public record UserSignedInEvent(Session Session) : INotification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
backend/src/Logitar.Master.EntityFrameworkCore/Handlers/Accounts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using Logitar.EventSourcing; | ||
using Logitar.Master.Application.Accounts.Events; | ||
using Logitar.Master.EntityFrameworkCore.Entities; | ||
using Logitar.Portal.Contracts.Users; | ||
using MediatR; | ||
using Microsoft.EntityFrameworkCore; | ||
|
||
namespace Logitar.Master.EntityFrameworkCore.Handlers; | ||
|
||
internal static class Accounts | ||
{ | ||
public class UserSignedInEventHandler : INotificationHandler<UserSignedInEvent> | ||
{ | ||
private readonly MasterContext _context; | ||
|
||
public UserSignedInEventHandler(MasterContext context) | ||
{ | ||
_context = context; | ||
} | ||
|
||
public async Task Handle(UserSignedInEvent @event, CancellationToken cancellationToken) | ||
{ | ||
User user = @event.Session.User; | ||
|
||
string id = new ActorId(user.Id).Value; | ||
ActorEntity? actor = await _context.Actors.SingleOrDefaultAsync(x => x.Id == id, cancellationToken); | ||
if (actor == null) | ||
{ | ||
actor = new(user); | ||
|
||
_context.Actors.Add(actor); | ||
} | ||
else | ||
{ | ||
actor.Update(user); | ||
} | ||
|
||
await _context.SaveChangesAsync(cancellationToken); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters