Пример #1
0
        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));
            }
        }
Пример #2
0
        public IHttpActionResult closeChat([FromBody] Message message)
        {
            //tell mudassir to send message with chatid and recieverid
            Debug.Print(message.Text + "-----user closes chat----" + message.RecieverId);
            ApplicationUser reciever = userService.findUserOnId(message.RecieverId);

            chatService.closeAllActiveChatsOfUser(message.RecieverId);
            message.Reciever = reciever;
            if (reciever != null)
            {
                reciever.available = true;
                userService.Update(reciever);
                this.chatService.changeActiveStatus(message.ChatId, false);
                this.eventService.chatClosedByUser(message);
            }

            Debug.Print("----close chat window-----" + User.Identity.Name);
            Consumer consumer = (Consumer)HttpContext.Current.Application[User.Identity.Name];

            Debug.Print(consumer + "-------consukmer her for despose");
            consumer?.Dispose();
            return(Ok());
        }