/// <summary> /// Posts the claim. /// </summary> /// <returns>The claim.</returns> /// <param name="claim">Claim.</param> public async Task <string> PostClaim(ClaimInputs claim) { if (claim == null) { throw new ArgumentNullException(nameof(claim), "Cannot be null"); } Console.WriteLine("[{0}] : Creating the claim # : [ {1} ] : with taskID : [ {2} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claim.claimNumber, claim.taskId); string serializedClaim = JsonConvert.SerializeObject(claim, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore }); var requestBody = new StringContent(serializedClaim, Encoding.UTF8, "application/json"); string accessToken = InMemoryStorage.Instance().StoredDriverToken; var httpClient = new HttpClient(); var requestMessage = new HttpRequestMessage { RequestUri = new Uri($"{_mbeUrl}api/claims?access_token={accessToken}"), Method = HttpMethod.Post, Content = requestBody }; requestMessage.Headers.Add("correlation_id", ApiHelpers.GetRandomString()); HttpResponseMessage responseMessage = await httpClient.SendAsync(requestMessage); if (_errorStatus.Contains(responseMessage.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchDriverToken(_mbeUrl); return(await PostClaim(claim)); } if (responseMessage.StatusCode != HttpStatusCode.OK && responseMessage.StatusCode != HttpStatusCode.Created) { return(string.Empty); } return(await responseMessage.Content.ReadAsStringAsync()); }
public async Task <object> PostSubmitDamages(string id, [FromBody] SubmitDamageInputs dataFromDg) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or empty"); } if (dataFromDg == null) { throw new ArgumentNullException(nameof(dataFromDg), "Cannot be null."); } Console.WriteLine( "[ {0} ] : SUBMIT DAMAGES : call made with claim ID : [ {1} ] and damages data : [ {2} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id, Convert.ToString(dataFromDg)); Console.WriteLine( "[ {0} ] : SUBMIT DAMAGES : Get claim call made to validate Claim in MBE with Claim ID : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id); string existingClaim = await _mbe.GetClaim(id); if (string.IsNullOrEmpty(existingClaim)) { return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent(string.Format("No claim found with ID {0}", id)), ReasonPhrase = "No content found with given claim Id" }); } ClaimInputs claimDataObj = JsonConvert.DeserializeObject <ClaimInputs>(existingClaim); if (!string.IsNullOrEmpty(dataFromDg.damageComment)) { HttpResponseMessage submitCommentsResponse = await _mbe.SubmitClaimComments(id, claimDataObj.claimNumber, claimDataObj.orgId, dataFromDg.damageComment); Console.WriteLine( $"[ {ApiHelpers.GetCurrentTimeStamp(DateTime.Now)} ] : SUBMIT ATTACHMENT COMMENTS RESULT: " + $"{submitCommentsResponse.Content.ReadAsStringAsync().Result}"); } var a2EHeader = new a2eHeaders { id = ApiHelpers.GetRandomString(), cid = ApiHelpers.GetRandomString(), messageType = "createestimaterequest" }; var a2EBody = new a2eBody { capturedDamage = dataFromDg.capturedDamage, vinDecodeFailed = claimDataObj.vinDecodeFailed, mileage = dataFromDg.mileage }; var dataToA2E = new dataToA2e { header = a2EHeader, claimContext = new ClaimContext { workAssignmentId = claimDataObj.workAssignmentPK, createdForProfileId = !string.IsNullOrEmpty(claimDataObj.externalId) ? claimDataObj.externalId : "477T2PPCOMPAPP2", orgId = claimDataObj.orgId }, body = a2EBody }; string publishingResults = await _eventManager.PublishEvent(dataToA2E); Console.WriteLine(publishingResults); return("Received damage data successfully"); }