Пример #1
0
        /// <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);
        }
Пример #2
0
        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
                }));
            }
        }