Click here to Skip to main content
15,798,508 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)

How do I create the relationship between the support team member and partner user in my chatHub and then save the messages that they have sent to one another in my SQL database. Note, I am using ASP.NET identity framework for my user roles and rights.


The issue that I am currently facing is establishing a relationship between the partner user and the support team member. I am also unsure of how to store the messages that are sent on the localhost in the database. Sending the messages to and from the localhosts is simple enough, but establishing the relationship between the specific support team member and the partner user is where things get tough. Note that I am using the ASP.NET identity framework in my project.

I am attempting to create a conversation subsystem within the current subsystem. The basic logical of the subsystem is as follows:

The ticket gets logged by the chatBot for the specific partner user.
The Ticket is assigned to a random support team member.
The support team member is notified that the ticket has been assigned to him and is prompted to start a conversation with the specific partner user.
The support team member views the chat subsystem where they can see all of the chats that they have had and the new partner user with whom they have to communicate.
The support team member enters the chat and starts the "support-conversation" with the partner user.
At the end of the conversation the partner user can submit feedback of the specific support-team member with which they had a conversation.
The implementation of the subsystem is similar to the following code that I found at GitHub - Limon-7/SignalRChat[^]

If you require any further clarification please ask :) Any help is greatly appreciated.

What I have tried:


using AutoDocs.Models;
using AutoDocs.ViewModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.SignalR;
using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace AutoDocs.ConversationHub
    public class ChatHub : Hub
        private readonly AppDbContext _dbContext;
        private readonly UserManager<ApplicationUser> _userManager;
        private readonly Support_Conversation _conversation;

        public ChatHub(AppDbContext dbContext, UserManager<ApplicationUser> userManager, Support_Conversation conversation)
            _dbContext = dbContext;
            _userManager = userManager;
            _conversation = conversation;

        public async Task SendMessage(string message, string receiverId)
            var id = _conversation.SenderId;
            message = _conversation.support_conversation_message;
            var senderId =  _userManager.FindByIdAsync(id).ToString();
            var chat = await _dbContext.Support_Conversations.FirstOrDefaultAsync(c => (c.SenderId == senderId && c.ReceiverId == receiverId) || (c.SenderId == receiverId && c.ReceiverId == senderId));

            if (chat == null)
                chat = new Support_Conversation
                    SenderId = senderId,
                    ReceiverId = receiverId

            await Clients.All.SendAsync("ReceiveMessage", message, senderId);

What I am attempting to do in the ChatHub is link the partner user and the support team member by their respective id's.


using AutoDocs.ConversationHub;
using AutoDocs.Models;
using AutoDocs.ViewModels;
using AutoMapper.Configuration;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using System.Security.Claims;
using System.Threading.Tasks;

namespace AutoDocs.Controllers
    public class ConverstationController : Controller

    // I would like to create a method that will save the messages that have been sent to the SQL Database 

Updated 30-Jun-23 8:08am
Graeme_Grant 30-Jun-23 21:57pm    
Are both the partner and team member assigned to the same channel?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900