// Construct and send the message that the logged in user wants to send. public static async Task<SendMessageResponse> SendMessageAsync(string accessToken, SendMessageRequest sendMessageRequest) { var sendMessageResponse = new SendMessageResponse { Status = SendMessageStatusEnum.NotSent }; using (var client = new HttpClient()) { using (var request = new HttpRequestMessage(HttpMethod.Post, Settings.SendMessageUrl)) { request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); request.Content = new StringContent(JsonConvert.SerializeObject(sendMessageRequest), Encoding.UTF8, "application/json"); using (HttpResponseMessage response = await client.SendAsync(request)) { if (response.IsSuccessStatusCode) { sendMessageResponse.Status = SendMessageStatusEnum.Sent; sendMessageResponse.StatusMessage = null; } else { sendMessageResponse.Status = SendMessageStatusEnum.Fail; sendMessageResponse.StatusMessage = response.ReasonPhrase; } } } } return sendMessageResponse; }
// Take data and put into Index view. public ActionResult Index(SendMessageResponse sendMessageResponse, UserInfo userInfo) { EnsureUser(ref userInfo); ViewBag.UserInfo = userInfo; ViewBag.MessageResponse = sendMessageResponse; return View(); }