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 }); } }
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)); } }
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> 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> 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 }); } }