-
-
Save dcomartin/5a70241fcd4b285ad52f82e2c7c78a1a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| public class AddMemberHandler | |
| { | |
| private const int MaxMembers = 100_000; | |
| private readonly IDbConnection _connection; | |
| public AddMemberHandler(IDbConnection connection) | |
| { | |
| _connection = connection; | |
| } | |
| public void Handle(Guid groupChatId, Guid userId) | |
| { | |
| using var trx = _connection.BeginTransaction(); | |
| var memberCount = _connection.ExecuteScalar<int>( | |
| "SELECT COUNT(*) FROM GroupChatMembers WHERE GroupChatId = @Id", | |
| new { Id = groupChatId }, trx); | |
| if (memberCount >= MaxMembers) | |
| throw new InvalidOperationException("GroupChat is full"); | |
| _connection.Execute( | |
| "INSERT INTO GroupChatMembers (GroupChatId, UserId) VALUES (@GroupChatId, @UserId)", | |
| new { GroupChatId = groupChatId, UserId = userId }, trx); | |
| trx.Commit(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment