// Construct and send the message that the logged in user wants to send. public static async Task<CreateEventResponse> CreateEventAsync(string accessToken, CreateEventRequest createEventRequest) { var createEventResponse = new CreateEventResponse { Status = CreateEventStatusEnum.NotCreated}; using (var client = new HttpClient()) { using (var request = new HttpRequestMessage(HttpMethod.Post, Settings.CreateEventUrl)) { request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); string test = JsonConvert.SerializeObject(createEventRequest.Event); request.Content = new StringContent(JsonConvert.SerializeObject(createEventRequest.Event), Encoding.UTF8, "application/json"); using (HttpResponseMessage response = await client.SendAsync(request)) { if (response.IsSuccessStatusCode) { createEventResponse.Status = CreateEventStatusEnum.Created; createEventResponse.StatusMessage = null; } else { createEventResponse.Status = CreateEventStatusEnum.Failed; createEventResponse.StatusMessage = response.ReasonPhrase; } } } } return createEventResponse; }
// Take data and put into Index view. public ActionResult Index(CreateEventResponse createEventResponse, EventInfo eventInfo) { ValidateInfo(ref eventInfo); ViewBag.EventInfo = eventInfo; ViewBag.CreateEventResponse = createEventResponse; return View(); }