Пример #1
0
        public async Task <IActionResult> CreateChat(CreateChat request)
        {
            var chat = new Chat()
            {
                UserName    = request.UserName,
                Content     = request.Content,
                DateCreated = DateTime.Now
            };

            _context.Chats.Add(chat);
            await _context.SaveChangesAsync();

            return(Json(new
            {
                status = true
            }));
        }
Пример #2
0
        public ActionResult Create()
        {
            //Remove the cookie from the request headers and reset the cookie to the current user's applicationcookie
            GetApplicationCookie();

            /*Search by User ID of Doctor == 2*/
            string id = "2";
            //The view needs to be sent a list of all the users so the client can select a user as the recipient in the view
            string requestAddress = "UserData/GetUsersByRoleId/" + id;
            HttpResponseMessage       response = client.GetAsync(requestAddress).Result;
            List <ApplicationUserDto> Doctors  = response.Content.ReadAsAsync <List <ApplicationUserDto> >().Result;
            CreateChat CreateChat = new CreateChat();

            CreateChat.Doctors = Doctors;
            Debug.WriteLine("Users object:" + JsSerializer.Serialize(CreateChat.Doctors));
            return(View(CreateChat));
        }
 public IChatModel Any(CreateChat request)
 {
     return(workflow.Create(request));
 }
Пример #4
0
        private void btnCreateChat_Click(object sender, RoutedEventArgs e)
        {
            CreateChat createChat = new CreateChat(usersApi);

            createChat.ShowDialog();
        }
Пример #5
0
        public ActionResult Create(CreateChat CreateChat, string RecipientId)
        {
            GetApplicationCookie();

            /*Separate Chat from message. Create new chat, then create new message.*/
            string SenderId = User.Identity.GetUserId();

            Debug.WriteLine("Recipient:" + RecipientId);
            Debug.WriteLine("CreateChat OBJECT: " + JsSerializer.Serialize(CreateChat));
            ChatDto NewChat = CreateChat.Chat;

            NewChat.DateCreated = DateTime.Now;

            //string to send request to the createchat API method with the id of the recipient and sender
            string requestAddress = "ChatData/CreateChat";

            //Create content which sends the Chat info as a Json object
            HttpContent content = new StringContent(JsSerializer.Serialize(NewChat));

            Debug.WriteLine("NEW CHAT OBJECT: " + JsSerializer.Serialize(NewChat));
            Debug.WriteLine("Request Address: " + requestAddress);
            //Headers are Chat headers that preceed the http Chat content (the json object).
            //Set the headervalue in  "content" to json
            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            //Send the data object to the request address and store Result in HttpResponseMessage
            HttpResponseMessage response = client.PostAsync(requestAddress, content).Result;

            //if response is success status code, display the details of the Chat in the "Show" view
            if (response.IsSuccessStatusCode)
            {
                Debug.WriteLine("SUCCESS ADDING CHAT");
                //ASSIGN New Chat Id Var FROM RETURNED CHAT ID
                int ChatId = response.Content.ReadAsAsync <int>().Result;
                /*Add the users to the chat (sender and recipient) via ChatData/AddUsersForChat/UserId api method */
                //Add sender
                string UserId = SenderId;
                requestAddress = "ChatData/AddUserForChat/" + UserId + "/" + ChatId;
                Debug.WriteLine("THIS CHAT ID IS: " + ChatId);
                content  = new StringContent("");
                response = client.PostAsync(requestAddress, content).Result;

                if (!response.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Error"));
                }

                //Add Recipient
                UserId         = RecipientId;
                requestAddress = "ChatData/AddUserForChat/" + UserId + "/" + ChatId;
                content        = new StringContent("");
                response       = client.PostAsync(requestAddress, content).Result;

                if (!response.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Error"));
                }

                //Add the initial message to the chat

                MessageDto NewMessage = new MessageDto
                {
                    SenderId = SenderId,
                    ChatId   = ChatId,
                    DateSent = DateTime.Now,
                    Content  = CreateChat.FirstMessage.Content,
                };

                requestAddress = "MessageData/CreateMessage";
                content        = new StringContent(JsSerializer.Serialize(NewMessage));
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                response = client.PostAsync(requestAddress, content).Result;

                //reads messageId from response and sends to show method

                if (!response.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Error"));
                }

                /*Add the message sender to the chat */

                else
                {
                    return(RedirectToAction("../Message/ChatMessages", new { id = ChatId }));
                }
            }

            else
            {
                return(RedirectToAction("Error"));
            }
        }