/// <summary> /// This method gets the estimate from MBE. /// </summary> /// <param name="claimId">Represents the claim id.</param> /// <returns>The serialized estimate.</returns> public async Task <string> GetEstimageForClaim(string claimId) { var estimateInputDataForMbe = new Dictionary <string, string> { { "claimId", claimId } }; var estimateInputData = JsonConvert.SerializeObject(estimateInputDataForMbe); var estimateInputContentJson = new StringContent(estimateInputData, Encoding.UTF8, "application/json"); HttpResponseMessage estimateResponse = await DownloadEstimateFromMbe(estimateInputContentJson); Console.WriteLine("[ {0} ] : GET ESTIMATE : Received response from MBE with reason phrase : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), estimateResponse.ReasonPhrase); if (_errorStatus.Contains(estimateResponse.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchDriverToken(_mbeUrl); estimateResponse = await DownloadEstimateFromMbe(estimateInputContentJson); } if (estimateResponse.ReasonPhrase == "Not Found") { return(null); } string downloadEstimateContent = await estimateResponse.Content.ReadAsStringAsync(); return(downloadEstimateContent); }
/// <summary> /// Async tast to post claim video from MBE using GetVideoUrlForClaim() /// Uses AXN token and Generate DRIVERS token if expires /// </summary> /// <param name="claimData">Represents the claim data.</param> /// <returns></returns> public async Task <string> GetClaimVideo(object claimData) { VideoInput videoData = new VideoInput { claim = claimData, videoVersion = 1, userAgent = "" }; string claimJsonData = JsonConvert.SerializeObject(videoData); var claimContentJson = new StringContent(claimJsonData, Encoding.UTF8, "application/json"); var videoRsponse = await GetVideoUrlForClaim(claimContentJson); Console.WriteLine("[ {0} ] : GET VIDEO : Response received from MBE with reason phrase as : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), videoRsponse.ReasonPhrase); if (_errorStatus.Contains(videoRsponse.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchDriverToken(_mbeUrl); videoRsponse = await GetVideoUrlForClaim(claimContentJson); } if (videoRsponse.ReasonPhrase == "Not Found") { return(null); } string videoResult = await videoRsponse.Content.ReadAsStringAsync(); return(videoResult); }
/// <summary> /// This method updates the vehivle VIN from a claim. /// </summary> /// <param name="vinInputData">Represents the vin input data.</param> /// <returns>The vehicle updation VIN response.</returns> public async Task <string> UpdateVehicleVin(vehicleUpdateInput vinInputData) { var jsonData = JsonConvert.SerializeObject(vinInputData); var jsonContent = new StringContent(jsonData, Encoding.UTF8, "application/json"); var vinDecodeData = await UpdateVehicleVintoMbe(jsonContent); Console.WriteLine("[ {0} ] : UPDATE VEHICLE : Response received from MBE with reason phrase as : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), vinDecodeData.ReasonPhrase); if (_errorStatus.Contains(vinDecodeData.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchDriverToken(_mbeUrl); vinDecodeData = await UpdateVehicleVintoMbe(jsonContent); } if (vinDecodeData.ReasonPhrase == "Not Found") { return(null); } var vinDecodeResults = vinDecodeData.Content.ReadAsStringAsync(); return(vinDecodeResults.Result); }
/// <summary> /// This method gets a get by it's ID. /// </summary> /// <returns>>The existing claim.</returns> /// <param name="claimId">Claim identifier.</param> public async Task <string> GetClaim(string claimId) { if (string.IsNullOrEmpty(claimId)) { throw new ArgumentNullException(nameof(claimId), "Cannot be null or empty."); } var claimResponse = await GetClaimFromMbe(claimId); Console.WriteLine("[ {0} ] : GET claim by ID : MBE endpoint returned with response phrase : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimResponse.ReasonPhrase); if (_errorStatus.Contains(claimResponse.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchAccessToken(_mbeUrl); claimResponse = await GetClaimFromMbe(claimId); } else if (claimResponse.ReasonPhrase == "Not Found") { return(null); } var claimResult = await claimResponse.Content.ReadAsStringAsync(); Console.WriteLine("[ {0} ] : GET claim by ID : response received from MBE is : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimResult); return(claimResult); }
public async Task <object> GetVideoUrl(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null."); } Console.WriteLine("[ {0} ] : GET VIDEO : Call made with claim ID [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id); Console.WriteLine("[ {0} ] : GET VIDEO : Checking if claim exists in MBE using GET CLAIM BY ID ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now)); try { string getClaim = await _mbe.GetClaim(id); if (string.IsNullOrEmpty(getClaim)) { 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" }); } object claimDataObj = JsonConvert.DeserializeObject(getClaim); string videoData = await _mbe.GetClaimVideo(claimDataObj); Console.WriteLine("[ {0} ] : GET VIDEO : Data received from MBE as : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), Convert.ToString(videoData)); if (string.IsNullOrEmpty(videoData)) { return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Could not fetch video for claim"), ReasonPhrase = "No content received from sunday sky for this claim" }); } var videoDataObj = JsonConvert.DeserializeObject(videoData); return(videoDataObj); } catch (Exception e) { Console.WriteLine( "[ {0} ] : GET VIDEO : Error occured while getting video for claim with error : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), e.Message); return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(e.Message), ReasonPhrase = e.Message }); } }
/// <summary> /// This method publishes an event to the configured queue. /// </summary> /// <param name="message">Represents the message body.</param> /// <returns>The result of the publishing.</returns> public Task <string> PublishEvent(dataToA2e message) { if (message == null) { throw new ArgumentNullException(nameof(message), "Cannot be null."); } return(Task.Factory.StartNew(() => { try { var factory = new ConnectionFactory { Uri = new Uri(_queueUrl), Ssl = { Version = SslProtocols.Tls12 } }; using (IConnection conn = factory.CreateConnection()) { using (IModel channel = conn.CreateModel()) { channel.BasicReturn += MqBasicReturn; string serializedMessage = JsonConvert.SerializeObject(message); var messageBody = Encoding.UTF8.GetBytes(serializedMessage); IBasicProperties basicproperties = channel.CreateBasicProperties(); basicproperties.Persistent = true; channel.BasicPublish(_exchangeName, _routingKey, basicProperties: basicproperties, mandatory: true, body: messageBody); Console.WriteLine("[ {0} ] : SUBMIT DAMAGES : Data sent to A2E : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), serializedMessage); channel.BasicReturn -= MqBasicReturn; } } return $"[ {ApiHelpers.GetCurrentTimeStamp(DateTime.Now)} ] The message has " + "been successfully published."; } catch (Exception e) { WebHook.RunAsync(e.Message).GetAwaiter().GetResult(); return $"Error while subitting the event to the excahnge {_exchangeName} " + $"with routing key {_routingKey}. Error message [ {e.Message} ]."; } })); }
/// <summary> /// This method calls the MBE api to update an existing claim. /// </summary> /// <param name="id">Represents the claim identifier.</param> /// <param name="claimUpdateData">Represents the claim data to update.</param> /// <returns>An instance of HttpResponseMessage with the request results.</returns> async Task <HttpResponseMessage> PutClaimToMbe(string id, HttpContent claimUpdateData) { HttpClient httpClient = new HttpClient(); string claimPutUrl = _mbeUrl + "api/claims/" + id + "?access_token=" + InMemoryStorage.Instance().StoredToken; Console.WriteLine("[ {0} ] : UPDATE CLAIM : Update claim request sent to MBE using URL : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimPutUrl); HttpResponseMessage claimPutResponse = await httpClient.PutAsync(claimPutUrl, claimUpdateData); return(claimPutResponse); }
/// <summary> /// Gets the claim from mbe. /// </summary> /// <returns>The claim from mbe.</returns> /// <param name="claimId">Claim identifier.</param> async Task <HttpResponseMessage> GetClaimFromMbe(string claimId) { HttpClient client = new HttpClient(); string inputUrl = _mbeUrl + "api/claims/" + claimId + "?access_token=" + InMemoryStorage.Instance().StoredToken; Console.WriteLine("[ {0} ] : GET claim by ID : MBE endpoint used to get claim details : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), inputUrl); var claimResponse = await client.GetAsync(inputUrl); return(claimResponse); }
/// <summary> /// This method calls the MBE api to submit a file. /// </summary> /// <param name="photoData">Represents the photo data.</param> /// <returns></returns> async Task <HttpResponseMessage> PostClaimPhotoToMbe(HttpContent photoData) { var client = new HttpClient(); string photoPostUrl = _mbeUrl + "api/Attachments/uploadImage?access_token=" + InMemoryStorage.Instance().StoredDriverToken; Console.WriteLine("[ {0} ] : POST PHOTO : Call made to MBE using URL : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), photoPostUrl); var photoUploadResponse = await client.PostAsync(photoPostUrl, photoData); return(photoUploadResponse); }
/// <summary> /// This method calls the MBE api in order to get the estimate. /// </summary> /// <param name="claimIdData">Represents the claim data.</param> /// <returns>The estimate response from MBE.</returns> private async Task <HttpResponseMessage> DownloadEstimateFromMbe(HttpContent claimIdData) { var httpClient = new HttpClient(); string downloadEstimateUrl = _mbeUrl + "api/Attachments/downloadEstimateReport?access_token=" + InMemoryStorage.Instance().StoredDriverToken; Console.WriteLine("[ {0} ] : GET ESTIMATE : Call made to MBE using URL : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), downloadEstimateUrl); HttpResponseMessage estimateFiles = await httpClient.PostAsync(downloadEstimateUrl, claimIdData); return(estimateFiles); }
/// <summary> /// This method calls the MBE api to update the vehicle VIN information. /// </summary> /// <param name="vinData">Represents the VIN data.</param> /// <returns></returns> async Task <HttpResponseMessage> UpdateVehicleVintoMbe(HttpContent vinData) { var client = new HttpClient(); string eagleVinUrl = _mbeUrl + "api/claims/updateClaimByEagleApiVin?access_token=" + InMemoryStorage.Instance().StoredDriverToken; Console.WriteLine("[ {0} ] : UPDATE VEHICLE : Request made to MBE using URL : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), eagleVinUrl); HttpResponseMessage updatedClaim = await client.PostAsync(eagleVinUrl, vinData); return(updatedClaim); }
/** * Private async method to get claim video data by calling MBE API * uses StoredDriverToken (DRIVER) to get required access * */ private async Task <HttpResponseMessage> GetVideoUrlForClaim(HttpContent videoData) { var client = new HttpClient(); string videoPostUrl = _mbeUrl + "api/UserActionUtilities/getVideoURLFromSundaySky?access_token=" + InMemoryStorage.Instance().StoredDriverToken; Console.WriteLine("[ {0} ] : GET VIDEO : Call made to MBE with URL : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), videoPostUrl); var videoPostResponse = await client.PostAsync(videoPostUrl, videoData); return(videoPostResponse); }
public async Task <object> GetById(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or empty."); } Console.WriteLine("[ {0} ] : GET CLAIM BY ID : call made with ID: [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id); try { //Get claim object from asyncTask string receivedClaimString = await _mbe.GetClaim(id); if (string.IsNullOrEmpty(receivedClaimString)) { Console.WriteLine("[ {0} ] : GET CLAIM BY ID : Claim not found in MBE for claim with ID: [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id); //return message with error code if no claim fetched with this id 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" }); } Console.WriteLine( "[ {0} ] : GET CLAIM BY ID : Claim found in MBE for claim with ID: [ {1} ] : and received response from MBE as [ {2} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id, Convert.ToString(receivedClaimString)); //convert string to claim object var claimDataObj = JsonConvert.DeserializeObject <ClaimInputs>(receivedClaimString); //convert claim object to required format (for DG) ClaimOutputs claimResponse = ApiHelpers.ConvertClaimData(claimDataObj); return(claimResponse); } catch (Exception e) { Console.WriteLine( "[ {0} ] : GET CLAIM BY ID : Error occured while while fetching claim details with ID [ {1} ] and error as : [ {2} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id, e.Message); return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(e.Message), ReasonPhrase = e.Message }); } }
/// <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()); }
/// <summary> /// This method updates an existing claim. /// </summary> /// <param name="id">Represents the claim identifier.</param> /// <param name="data">Represents the claim data.</param> /// <returns>The recently created claim serialized.</returns> public async Task <string> UpdateClaim(string id, object data) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or emtpy."); } if (data == null) { throw new ArgumentNullException(nameof(data), "Cannot be null."); } string jsonData = JsonConvert.SerializeObject(data); var jsonContent = new StringContent(jsonData, Encoding.UTF8, "application/json"); HttpResponseMessage claimPutResponse = await PutClaimToMbe(id, jsonContent); Console.WriteLine("[ {0} ] : UPDATE CLAIM : Received response from MBE with reason phrase as : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimPutResponse.ReasonPhrase); if (_errorStatus.Contains(claimPutResponse.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchAccessToken(_mbeUrl); claimPutResponse = await PutClaimToMbe(id, jsonContent); } if (claimPutResponse.ReasonPhrase == "Not Found") { return(null); } string claimPutResult = await claimPutResponse.Content.ReadAsStringAsync(); Console.WriteLine("[ {0} ] : UPDATE CLAIM : Received response from MBE with updated claim as : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimPutResult); return(claimPutResult); }
public async Task <object> SubmitAssignment([FromBody] ClaimInputs claimData) { try { Console.WriteLine("[{0}] submitAssignment : Creating the claim : [{1}] for task Id : [{2}]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimData.claimNumber, claimData.taskId); if (claimData == null) { throw new ArgumentNullException(nameof(claimData), "Cannot be null"); } ValidationResults validationResult = _claimValidators.ValidateClaim(claimData); if (!validationResult.ValidationsPassed) { return(StatusCode((int)HttpStatusCode.BadRequest, validationResult)); } string createdClaim = await _mbe.PostClaim(claimData); if (string.IsNullOrEmpty(createdClaim)) { return(StatusCode((int)HttpStatusCode.InternalServerError, new { message = "The MBE core was not able to process the request." })); } var claimPutDataObj = JsonConvert.DeserializeObject <ClaimInputs>(createdClaim); ClaimOutputs claimPutOutput = ApiHelpers.ConvertClaimData(claimPutDataObj); return(StatusCode((int)HttpStatusCode.Created, claimPutOutput)); } catch (Exception exc) { Console.WriteLine($"[ {ApiHelpers.GetCurrentTimeStamp(DateTime.Now)} ] : PostClaim : Error while posting a new claim. Error message: {exc.Message}"); return(StatusCode((int)HttpStatusCode.InternalServerError, exc)); } }
/// <summary> /// This method abstracts the orchestration to add a comment to a given claim. /// </summary> /// <returns>The claim comments.</returns> /// <param name="claimId">Represents the claim id.</param> /// <param name="claimNumber">Represents the claim number.</param> /// <param name="orgId">Represents the organization id.</param> /// <param name="comments">Represents the comments text.</param> public async Task <HttpResponseMessage> SubmitClaimComments(string claimId, string claimNumber, string orgId, string comments) { if (string.IsNullOrEmpty(claimId) || claimId.Trim().Length == 0) { throw new ArgumentNullException(nameof(claimId), NullEmptyArgumentMessage); } if (string.IsNullOrEmpty(claimNumber) || claimNumber.Trim().Length == 0) { throw new ArgumentNullException(nameof(claimNumber), NullEmptyArgumentMessage); } if (string.IsNullOrEmpty(orgId) || orgId.Trim().Length == 0) { throw new ArgumentNullException(nameof(orgId), NullEmptyArgumentMessage); } if (string.IsNullOrEmpty(comments) || comments.Trim().Length == 0) { throw new ArgumentNullException(nameof(comments), NullEmptyArgumentMessage); } string resourceUrl = $"{_mbeUrl}api/claims/{claimId}/attachmentcomments?access_token={InMemoryStorage.Instance().StoredToken}"; Console.WriteLine($"[ {ApiHelpers.GetCurrentTimeStamp(DateTime.Now)} ] : POST ATTACHMENT COMMENT BY ID : " + $"{claimId} - Resource URL [ {resourceUrl} ]"); var httpClient = new HttpClient(); var attComment = new { comments, claimNumber, orgId, synched = false }; var requestBody = new StringContent(JsonConvert.SerializeObject(attComment), Encoding.UTF8, "application/json"); HttpResponseMessage responseMessage = await httpClient.PostAsync(resourceUrl, requestBody); return(responseMessage); }
/// <summary> /// Async tast to post claim claim video from MBE using GetVideoUrlForClaim() /// Uses AXN token and Generate DRIVERS token if expires /// </summary> /// <param name="photoData">Represents the photo data.</param> /// <returns>The serialized response from MBE</returns> public async Task <string> PostClaimPhoto(HttpContent photoData) { HttpResponseMessage photoUploadResponse = await PostClaimPhotoToMbe(photoData); Console.WriteLine("[ {0} ] : POST PHOTO : Response received from MBE with reason phrase as : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), photoUploadResponse.ReasonPhrase); if (_errorStatus.Contains(photoUploadResponse.ReasonPhrase, StringComparer.OrdinalIgnoreCase)) { await InMemoryStorage.Instance().FetchDriverToken(_mbeUrl); photoUploadResponse = await PostClaimPhotoToMbe(photoData); } if (photoUploadResponse.ReasonPhrase == "Not Found") { return(null); } string photoUploadResult = await photoUploadResponse.Content.ReadAsStringAsync(); return(photoUploadResult); }
public async Task <object> UpdateVehicle(string id, [FromBody] vehicleUpdateData dataForVehicleUpdate) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or empty."); } if (dataForVehicleUpdate == null) { throw new ArgumentNullException(nameof(dataForVehicleUpdate), "Cannot be null."); } Console.WriteLine($"[ {ApiHelpers.GetCurrentTimeStamp(DateTime.Now)} ] - updateVehicle to the claim id {id} and VIN {dataForVehicleUpdate.vin}"); Console.WriteLine( "[ {0} ] : UPDATE VEHICLE : Update vehicle call made with claim ID [ {1} ] and Data [ {2} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id, Convert.ToString(dataForVehicleUpdate)); Console.WriteLine("[ {0} ] : UPDATE VEHICLE : Checking if claim exists in MBE using GET CLAIm BY ID ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now)); try { if (string.IsNullOrEmpty(dataForVehicleUpdate.vin)) { return(StatusCode((int)HttpStatusCode.BadRequest, new ErrorResponse { message = "The vehicle VIN cannot be null or emtpy." })); } string existingClaim = await _mbe.GetClaim(id); if (string.IsNullOrEmpty(existingClaim)) { return(StatusCode((int)HttpStatusCode.NotFound, new ErrorResponse { message = $"No claim found with ID {id}" })); } vehicleUpdateInput dataToUpdate = new vehicleUpdateInput() { vin = dataForVehicleUpdate.vin, id = id }; string vinUpdateResponse = await _mbe.UpdateVehicleVin(dataToUpdate); Console.WriteLine("[ {0} ] : UPDATE VEHICLE : Response received from MBE for updating VIN : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), vinUpdateResponse); var updatedClaimDataObj = JsonConvert.DeserializeObject <ClaimInputs>(vinUpdateResponse); ClaimOutputs updatedClaim = ApiHelpers.ConvertClaimData(updatedClaimDataObj); return(updatedClaim); } catch (Exception e) { Console.WriteLine( "[ {0} ] : UPDATE VEHICLE : Error occured while while updating claim with VIN. error : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), e.Message); return(StatusCode((int)HttpStatusCode.InternalServerError, new ErrorResponse { exception = e })); } }
public async Task <object> UpdateVehicleOnClaim(string id, [FromBody] UpdateVehicleOnClaimRequest vehicleData) { if (string.IsNullOrEmpty(id)) { return(StatusCode((int)HttpStatusCode.BadRequest, new ErrorResponse { message = $"The claim id cannot be null or emtpy." })); } if (vehicleData == null) { return(StatusCode((int)HttpStatusCode.BadRequest, new ErrorResponse { message = $"The vehicle data cannot be null." })); } Console.WriteLine( "[ {0} ] : UpdateVehicleOnClaim invoked for the claim id : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id); try { var mbeUpdateVehicleRequest = new UpdateVehicleOnClaimMbeRequest { assignmentVehicleMake = vehicleData.make, assignmentVehicleYear = vehicleData.year, assignmentVehicleModel = vehicleData.model, vehicleFileId = vehicleData.fileId, vehicleStyleCode = vehicleData.styleCode, vehicleVIN = vehicleData.vinNumber, estimateVehicleVIN = vehicleData.vinNumber, estimateVehicleMake = vehicleData.make, estimateVehicleYear = vehicleData.year, estimateVehicleModel = vehicleData.model }; string claimUpdateResponse = await _mbe.UpdateClaim(id, mbeUpdateVehicleRequest); if (string.IsNullOrEmpty(claimUpdateResponse)) { return(StatusCode((int)HttpStatusCode.NotFound, new ErrorResponse { message = $"The claim id: {id} does not exist in MBE." })); } var claimPutDataObj = JsonConvert.DeserializeObject <ClaimInputs>(claimUpdateResponse); ClaimOutputs claimPutOutput = ApiHelpers.ConvertClaimData(claimPutDataObj); return(claimPutOutput); } catch (Exception e) { Console.WriteLine( "[ {0} ] : UpdateVehicleOnClaim : Error occured while getting estimate for claim with error : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), e.Message); return(StatusCode((int)HttpStatusCode.InternalServerError, new ErrorResponse { message = e.Message, exception = e })); } }
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"); }
public async Task <object> GetEstimateForClaim(string id) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or emtpy."); } Console.WriteLine("[ {0} ] : GET ESTIMATE : Call made with claim id [{1}]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id); Console.WriteLine("[ {0} ] : GET ESTIMATE : Calling GET CLAIM BY ID to validate claim ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now)); try { 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); string downloadedEstimate = await _mbe.GetEstimageForClaim(id); Console.WriteLine("[ {0} ] : GET ESTIMATE : Received response from MBE as : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), Convert.ToString(downloadedEstimate)); if (string.IsNullOrEmpty(downloadedEstimate)) { return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Unable to get estimate for this claim"), ReasonPhrase = "Unable to get estimate for this claim" }); } estimateFilesOutput estimateFileOutPut = JsonConvert.DeserializeObject <estimateFilesOutput>(downloadedEstimate); var estimateOutput = new EstimateOutput { estimateTotals = new estimateTotals { estimateNetTotal = claimDataObj.estimateNetTotal, currency = "USD" }, estimateDocuments = new estimateDocuments { contentType = estimateFileOutPut.type, filename = estimateFileOutPut.name, fileBase64 = estimateFileOutPut.content } }; Console.WriteLine("[ {0} ] : GET ESTIMATE : Estimate data sent to APP as : [ {1} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), Convert.ToString(estimateOutput)); return(estimateOutput); } catch (Exception e) { Console.WriteLine( "[ {0} ] : GET ESTIMATE : Error occured while getting estimate for claim with error : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), e.Message); return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(e.Message), ReasonPhrase = e.Message }); } }
public async Task <object> PostPhotoData(string id, [FromForm] photoDataInput photoMetadata, [FromForm] photoFileInputs fileData) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or empty."); } if (photoMetadata == null) { throw new ArgumentNullException(nameof(photoMetadata), "Cannot be null."); } if (fileData == null) { throw new ArgumentNullException(nameof(fileData), "Cannot be null."); } Console.WriteLine( "[ {0} ] : POST PHOTO : call made with claim ID : [ {1} ] , photo meta data [ {2} ] and with photo", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), id, Convert.ToString(photoMetadata)); PhotoFormData photoFormData = JsonConvert.DeserializeObject <PhotoFormData>(photoMetadata.metadata); string base64Stream = null; if (fileData.photo.Length > 0) { using (var ms = new MemoryStream()) { fileData.photo.CopyTo(ms); var fileBytes = ms.ToArray(); base64Stream = Convert.ToBase64String(fileBytes); Console.WriteLine("[ {0} ] : POST PHOTO : Photo data converted in to Base64 memory stream", ApiHelpers.GetCurrentTimeStamp(DateTime.Now)); } } string fileAttachmentType; string fileName = fileData.photo.FileName; string contentType = fileData.photo.ContentType; if (fileName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase) && contentType == "text/plain") { fileAttachmentType = "StatisticFile"; } else { fileAttachmentType = "UserUpload"; } Console.WriteLine("[ {0} ] : POST PHOTO : Calling GET CLAIM BY ID to validate claim", ApiHelpers.GetCurrentTimeStamp(DateTime.Now)); try { string getClaim = await _mbe.GetClaim(id); if (string.IsNullOrEmpty(getClaim)) { 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>(getClaim); var parametersToMbe = new PhotoInputsForMbe { data = base64Stream, fileName = fileName, attachmentType = fileAttachmentType, latitude = photoFormData.latitude, longitude = photoFormData.longitude, contentType = contentType, appName = "Digital Garage", userName = claimDataObj.userName, claimNumber = claimDataObj.claimNumber, orgId = claimDataObj.orgId }; var newDataForMbe = new Dictionary <string, PhotoInputsForMbe> { { "parameters", parametersToMbe } }; Console.WriteLine("[ {0} ] : POST PHOTO : Photodata prepared to send MBE : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), Convert.ToString(newDataForMbe)); string photoData = JsonConvert.SerializeObject(newDataForMbe); var photoContentJson = new StringContent(photoData, Encoding.UTF8, "application/json"); string photoResponseData = await _mbe.PostClaimPhoto(photoContentJson); Console.WriteLine("[ {0} ] : POST PHOTO : Received data from MBE : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), Convert.ToString(photoResponseData)); if (string.IsNullOrEmpty(photoResponseData)) { return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Unable to upload photo, please try again"), ReasonPhrase = "Unable to upload photo" }); } var photoDataObj = JsonConvert.DeserializeObject(photoResponseData); return(photoDataObj); } catch (Exception e) { Console.WriteLine( "[ {0} ] : POST PHOTO : Error occured while posting photos for claim with error : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), e.Message); return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(e.Message), ReasonPhrase = e.Message }); } }
public async Task <object> UpdateClaim(string id, [FromBody] object dataForUpdate) { if (string.IsNullOrEmpty(id)) { throw new ArgumentNullException(nameof(id), "Cannot be null or empty."); } if (dataForUpdate == null) { throw new ArgumentNullException(nameof(dataForUpdate), "Cannot be null."); } Console.WriteLine("[ {0} ] : UPDATE CLAIM : Call made with data [ {1} ] and ID [ {2} ] ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), Convert.ToString(dataForUpdate), id); Console.WriteLine("[ {0} ] : UPDATE CLAIM : Checking if claim exists in MBE using GET CLAIm BY ID ", ApiHelpers.GetCurrentTimeStamp(DateTime.Now)); try { 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" }); } string claimPutResponse = await _mbe.UpdateClaim(id, dataForUpdate); Console.WriteLine("[ {0} ] : UPDATE CLAIM : Update claim response received from MBE as : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), claimPutResponse); if (string.IsNullOrEmpty(claimPutResponse)) { return(new HttpResponseMessage(HttpStatusCode.NotFound) { Content = new StringContent("Error occured while updating claim"), ReasonPhrase = "Error occured while updating claim" }); } var claimPutDataObj = JsonConvert.DeserializeObject <ClaimInputs>(claimPutResponse); ClaimOutputs claimPutOutput = ApiHelpers.ConvertClaimData(claimPutDataObj); return(claimPutOutput); } catch (Exception e) { Console.WriteLine( "[ {0} ] : UPDATE CLAIM : Error occured while while updating claim. error : [ {1} ]", ApiHelpers.GetCurrentTimeStamp(DateTime.Now), e.Message); return(new HttpResponseMessage(HttpStatusCode.InternalServerError) { Content = new StringContent(e.Message), ReasonPhrase = e.Message }); } }