コード例 #1
0
        public async Task LeaveChannel(Guid channelId)
        {
            var currentUserId = _authService.GetAuthorizedUserId();
            var channelUser   = await DbContext.ChatChannelUsers
                                .Include(cu => cu.User)
                                .FirstOrDefaultAsync(cu => cu.ChannelId == channelId && cu.UserId == currentUserId);

            if (channelUser == null)
            {
                throw new EntityNotFoundException("User doesn't belong to this group");
            }

            DbContext.ChatChannelUsers.Remove(channelUser);
            await DbContext.SaveChangesAsync();

            await _chatProvider.UserLeftFromChannel(channelUser.User, channelId);
        }