public Message SendChatMessage(Message message, ApplicationUser sender, ApplicationUser reciever) { int?chatId2 = chatService.getChatIdOfUsers(sender.Id, reciever.Id); Debug.Print("Chat id is " + chatId2); if (chatId2 == null) { Debug.Print("Chat id 2 is null but how--" + chatId2); Chat chat = new Chat(); chat.UserOneId = sender.Id; chat.UserTwoId = reciever.Id; chat.active = true; Debug.Print("chat details----" + chat.ToString()); chatId2 = chatService.Save(chat); } message.SenderId = sender.Id; if (message.RecieverId.IsNullOrWhiteSpace()) { message.RecieverId = reciever.Id; } message.SentTime = DateTime.Now; message.ChatId = chatId2; Message msgWithId = messageService.Save(message); return(msgWithId); }
public void AssignNextRequestInQueueToHr() { HttpContext.Application["Time"] = DateTime.Now; Debug.Print("in hr get next request---"); ChatRequest chatRequest = this.chatRequestService.NextChatRequestInQueue(); ApplicationUser reciever = UserManager.FindById(User.Identity.GetUserId()); ApplicationUser sender = UserManager.FindById(chatRequest.UserId); Debug.Print(chatRequest + "------cgat rwq"); Producer producer = new Producer("messageexchange", ExchangeType.Direct); if (chatRequest != null) { int messageSize = this.messageService.GetMessageSizeOfChatRequestUser(chatRequest.UserId); this.chatRequestService.delete(chatRequest); int?chatId2 = null; chatId2 = chatService.getChatIdOfUsers(sender.Id, reciever.Id); Debug.Print("Chat id is " + chatId2); List <Message> messages = new List <Message>(); if (chatId2 == null) { Debug.Print("Chat id 2 is null but how--" + chatId2); Chat chat = new Chat(); chat.UserOneId = sender.Id; chat.UserTwoId = reciever.Id; chat.active = true; chatId2 = chatService.Save(chat); } else { this.chatService.changeActiveStatus(chatId2, true); } if (messageSize > 0) { messages = messageService.GetMessagesOfChatRequestUser(sender.Id, reciever.Id, chatId2); } else { Message message = new Message(); message.Text = "Hello Agent,I want to chat with you"; message.RecieverId = reciever.Id; message.SenderId = sender.Id; message.SentTime = DateTime.Now; message.ChatId = chatId2; message = messageService.Save(message); messages.Add(message); } foreach (Message msgWithId in messages) { if (producer.ConnectToRabbitMQ()) { producer.send(msgWithId); this.eventService.NotifyHrAboutChat(msgWithId); } } this.eventService.hrAvailableNotification(sender.DeviceCode); } }