public async Task <ChatMessageModel> CreateMessage(string userId, ChatMessageModel model)
        {
            var members = _chatChannelMemberRepository.GetAll()
                          .Where(_ => _.ChannelId == model.ChannelId);

            if (!await members.AnyAsync(_ => _.UserId == userId))
            {
                throw new NotFoundException("Channel not found or user doesn't have access.");
            }

            var user = await _userService.GetUserAsync(userId);

            model.Username   = user.Username;
            model.CreatedBy  = user.Id;
            model.CreateDate = DateTime.UtcNow;

            var message = _mapper.Map <ChatMessage>(model);
            await _chatMessageRepository.AddAsync(message);

            var createdMessage = _mapper.Map <ChatMessageModel>(message);

            var otherMembers = await members.Where(_ => _.UserId != userId)
                               .Select(_ => _.UserId).ToListAsync();

            foreach (var member in otherMembers)
            {
                await _notificationService.CreateNotification(new NotificationModel
                {
                    Subject          = $"New message from {user.Username}",
                    Description      = $"{createdMessage.Message}",
                    CreatedBy        = user.Id,
                    AssignedToUserId = member,
                    CreatedDate      = DateTime.UtcNow,
                    IsRead           = false
                });
            }

            _pushService.PushChatMessage(otherMembers, createdMessage);

            return(createdMessage);
        }