public void Connect(string userName, string email) { emailIDLoaded = email; var id = Context.ConnectionId; var uow = new XpoDAO().ProvideUnitOfWork(); var result = new XPCollection <ChatUserDetail>(uow); var item = result.FirstOrDefault(x => x.EmailID == email); if (item != null) { uow.Delete(item); //result.Remove(item); uow.CommitChanges(); // Disconnect Clients.All.onUserDisconnectedExisting(item.ConnectionId, item.UserName); } var Users = result; if (Users.Where(x => x.EmailID == email).ToList().Count == 0) { var userdetails = new ChatUserDetail(uow) { ConnectionId = id, UserName = userName, EmailID = email }; uow.CommitChanges();; // send to caller var connectedUsers = result; var CurrentMessage = new XPCollection <ChatMessageDetail>(uow);// dc.ChatMessageDetails.ToList(); List <TempChatMessageDetail> lstTempChatMessageDetail = new List <TempChatMessageDetail>(); foreach (var currentMessage in CurrentMessage) { lstTempChatMessageDetail.Add(new TempChatMessageDetail() { EmailID = currentMessage.EmailID, Message = currentMessage.Message, UserName = currentMessage.UserName }); } List <TempChatUserDetail> lstTempChatUserDetail = new List <TempChatUserDetail>(); foreach (var user in connectedUsers) { var tempChatUserDetail = new TempChatUserDetail() { ConnectionId = user.ConnectionId, EmailID = user.EmailID, UserName = user.UserName }; lstTempChatUserDetail.Add(tempChatUserDetail); } Clients.Caller.onConnected(id, userName, lstTempChatUserDetail, lstTempChatMessageDetail);//connectedUsers } // send to all except caller client Clients.AllExcept(id).onNewUserConnected(id, userName, email); }
public override System.Threading.Tasks.Task OnDisconnected(bool stopCalled) { var uow = new XpoDAO().ProvideUnitOfWork(); var result = new XPCollection <ChatUserDetail>(uow); var item = result.FirstOrDefault(x => x.ConnectionId == Context.ConnectionId); if (item != null) { //result.Remove(item); uow.Delete(item); uow.CommitChanges(); var id = Context.ConnectionId; Clients.All.onUserDisconnected(id, item.EmailID); //Clients.All.onUserDisconnected(id, item.UserName); } return(base.OnDisconnected(stopCalled)); }