public JsonResult CloseChat(string activeUser) { Debug.Print(activeUser + "-----------active user"); ApplicationUser user1 = (ApplicationUser)Session["user"]; ApplicationUser user2 = userService.findUserOnId(user1.Id); if (!activeUser.IsNullOrWhiteSpace() && activeUser != "null")//2nd exp as it used to pass null as string like "null" { Debug.Print(user2.Id + "----active user not null chat " + activeUser); int?chatId = chatService.getChatIdOfUsers(activeUser, user2.Id); Debug.Print("chat id is----" + chatId); if (chatId != null) { chatService.changeActiveStatus(chatId, false); } eventService.hrClosedChat(userService.findUserOnId(activeUser).UserName); } if (this.chatRequestService.ChatRequestsSize() > 0) { return(Json(true, JsonRequestBehavior.AllowGet)); } else { user2.available = true; this.userService.Update(user2); return(Json(false, JsonRequestBehavior.AllowGet)); } }
public IHttpActionResult sendmsg([FromBody] Message message) { var Name1 = User.Identity.Name; Task <ApplicationUser> user = UserManager.FindByNameAsync(Name1); ApplicationUser sender = user.Result; message.SenderId = sender.Id; ApplicationUser reciever; if (string.IsNullOrEmpty(message.RecieverId) && this.chatService.IsActive(message.ChatId)) { Debug.Print(message.RecieverId); } Debug.Print(message.ChatId + "--------chat id by mudassir-----" + message.Text); if (message.ChatId == 0 || !this.chatService.IsActive(message.ChatId)) { reciever = ProcessMessage(message, sender); Debug.Print("it shud be here-----"); if (reciever == null) { Debug.Print("process msg rerurned null----"); return(Ok()); } } else { reciever = userService.findUserOnId(message.RecieverId); } Producer producer = new Producer("messageexchange", ExchangeType.Direct); Message msgWithId = new Message(); if (producer.ConnectToRabbitMQ()) { msgWithId = SendChatMessage(message, sender, reciever); if (!chatService.IsActive(msgWithId.ChatId)) { chatService.changeActiveStatus(msgWithId.ChatId, true); } producer.send(msgWithId); this.eventService.NotifyHrAboutChat(msgWithId); this.eventService.changeToggle(reciever); } return(Ok(msgWithId)); }
public JsonResult CloseChat(string activeUser) { ApplicationUser user1 = (ApplicationUser)Session["user"]; ApplicationUser user2 = userService.findUserOnId(user1.Id); //get user from this db context if (!activeUser.IsNullOrWhiteSpace() && activeUser != "null") //2nd exp as it used to pass null as string like "null" { int?chatId = chatService.getChatIdOfUsers(activeUser, user2.Id); if (chatId != null) { chatService.changeActiveStatus(chatId, false); } chatService.closeAllActiveChatsOfUser(user1.Id); eventService.hrClosedChat(userService.findUserOnId(activeUser).UserName); } else { Chat chat = this.messageService.getLatestChatOfUser(user1.Id); ApplicationUser user = chatService.GetUserFromChatIdOtherThanPassedUser(chat?.Id, user1.Id); chatService.closeAllActiveChatsOfUser(user1.Id); eventService.hrClosedChat(user.UserName); } if (this.chatRequestService.ChatRequestsSize() > 0) { return(Json(true, JsonRequestBehavior.AllowGet)); } else { user2.available = true; this.userService.Update(user2); eventService.changeToggle(user2); return(Json(false, JsonRequestBehavior.AllowGet)); } }