public async Task <ActionResult <ExistingChatDTO> > CreateMessage([FromBody] ExistingChatDTO data)
        {
            string messageText = data.chatMessage;
            int    chatID      = data.ChatID;
            var    currentUser = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (ModelState.IsValid)
            {
                Message newMessage = new Message();
                newMessage.MessageText = messageText;
                newMessage.SenderID    = currentUser;
                newMessage.SentTime    = DateTime.Now;
                _context.Add(newMessage);
                await _context.SaveChangesAsync();

                ChatMessage newChatMesssage = new ChatMessage();
                newChatMesssage.ChatID    = chatID;
                newChatMesssage.MessageID = newMessage.MessageID;
                _context.Add(newChatMesssage);
                await _context.SaveChangesAsync();

                Chat updateChat = _context.Chats.Where(i => i.ChatID == chatID).FirstOrDefault();
                updateChat.LastActivity = DateTime.Now;
                _context.Update(updateChat);
                await _context.SaveChangesAsync();

                int selectedChat = chatID;

                return(RedirectToAction("Index", "Chat", new { @selectedChat = chatID }));
            }
            return(RedirectToAction(nameof(Index)));
        }
        public async Task <ActionResult <ExistingChatDTO> > DeleteChatDTOAsync([FromBody] ExistingChatDTO DeleteChatDTO)
        {
            int chatID = DeleteChatDTO.ChatID;

            await DeleteChat(chatID);

            return(View());
        }
        public async Task <ActionResult <ExistingChatDTO> > AddChatUsers([FromBody] ExistingChatDTO updateChatDTo)
        {
            string[] selectedChatUsers = updateChatDTo.selectedChatUsers;
            int      chatID            = updateChatDTo.ChatID;
            string   chatTitleInput    = updateChatDTo.ChatTitle;

            var currentUser = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (ModelState.IsValid)
            {
                Chat updatingChat = _context.Chats.Where(i => i.ChatID == chatID).FirstOrDefault();
                await CreateChatUsers(selectedChatUsers, currentUser, updatingChat);

                if (!string.IsNullOrEmpty(chatTitleInput))
                {
                    updatingChat.ChatTitle = chatTitleInput;
                    _context.Update(updatingChat);
                    await _context.SaveChangesAsync();
                }
                return(RedirectToAction("Index", "Chat", new { @selectedChat = chatID }));
            }
            return(RedirectToAction(nameof(Index)));
        }