public async Task <ActionResult> UpdateShipmentCode([FromBody] ShipmentGeoCodes shipmentGeoCodes) { QuincusResponse quincusResponse = null; QuincusTokenDataResponse quincusTokenDataResponse = QuincusService.GetToken(new UPS.Quincus.APP.Configuration.QuincusParams() { endpoint = configuration["Quincus:TokenEndPoint"], password = configuration["Quincus:Password"], username = configuration["Quincus:UserName"], }); if (quincusTokenDataResponse.ResponseStatus) { quincusResponse = QuincusService.GetGeoCodeReponseFromQuincus(new UPS.Quincus.APP.Request.QuincusGeoCodeDataRequest() { endpoint = configuration["Quincus:GeoCodeEndPoint"], batchIDList = shipmentGeoCodes.geoCode, quincusTokenData = quincusTokenDataResponse.quincusTokenData }); if (quincusResponse.ResponseStatus) { if (quincusResponse.QuincusReponseData != null) { IList <Geocode> geocodes = quincusResponse.QuincusReponseData.geocode; string TranslatedCode = geocodes[0].translated_adddress; return(Ok(quincusResponse.QuincusReponseData)); } } } else { //AuditEventEntry.WriteEntry(new Exception(quincusTokenDataResponse.exception.ToString())); return(Ok(quincusTokenDataResponse.exception)); } return(Ok("Error")); }
public async Task <ActionResult> GetTranslationAddress([FromBody] List <ShipmentDataRequest> _shipmentDataRequest) { int wid = 0; if (_shipmentDataRequest.Any()) { wid = _shipmentDataRequest.FirstOrDefault().WFL_ID; } QuincusTranslatedAddressResponse quincusTranslatedAddressResponse = new QuincusTranslatedAddressResponse(); QuincusParams quincusParams = new UPS.Quincus.APP.Configuration.QuincusParams() { endpoint = configuration["Quincus:TokenEndPoint"], password = configuration["Quincus:Password"], username = configuration["Quincus:UserName"], chunkSize = int.TryParse(configuration["Quincus:BatchSize"], out int size) == true ? size : 10, }; QuincusTokenDataResponse quincusTokenDataResponse = QuincusService.GetToken(quincusParams); if (quincusTokenDataResponse.ResponseStatus) { List <ShipmentWorkFlowRequest> shipmentWorkFlowRequests = _shipmentDataRequest.Select(_ => new ShipmentWorkFlowRequest() { id = _.ID, rcV_ADR_TE = _.RCV_ADR_TE, dsT_CTY_TE = _.DST_CTY_TE, wfL_ID = _.WFL_ID, pkG_NR_TE = _.PKG_NR_TE, rcV_CPY_TE = _.RCV_CPY_TE, dsT_PSL_TE = _.DST_PSL_TE }).ToList(); this._quincusAddressTranslationRequest.shipmentWorkFlowRequests = shipmentWorkFlowRequests; this._quincusAddressTranslationRequest.token = quincusTokenDataResponse.quincusTokenData.token; quincusTranslatedAddressResponse = QuincusService.GetTranslationAddress(this._quincusAddressTranslationRequest, quincusParams); if (quincusTranslatedAddressResponse.Response) { var getAddressTranslation = quincusTranslatedAddressResponse.ResponseData; List <string> batchIds = new List <string>(); Dictionary <string, string> shipmentDetailsDictionary = new Dictionary <string, string>(); quincusTranslatedAddressResponse.ResponseData.ForEach(batches => { batchIds.Add(batches.batch_id); batches.addresses.ForEach(address => { shipmentDetailsDictionary.Add(address.id, address.rcV_CPY_TE); }); }); var QuincusResponse = QuincusService.GetGeoCodeReponseFromQuincus(new UPS.Quincus.APP.Request.QuincusGeoCodeDataRequest() { endpoint = configuration["Quincus:GeoCodeEndPoint"], batchIDList = batchIds, quincusTokenData = quincusTokenDataResponse.quincusTokenData, ShipmentDetailsDictionary = shipmentDetailsDictionary }); if (QuincusResponse.ResponseStatus) { // Insert Address into AddressBook _addressBookService.InsertAddress(QuincusResponse.QuincusReponseDataList, shipmentDetailsDictionary); try { var requestIds = _shipmentDataRequest.Select(_ => _.ID).ToList(); List <ShipmentDataRequest> existingShipmentDetails = this._context.shipmentDataRequests .Where(ShpDetail => ShpDetail.WFL_ID == wid && (ShpDetail.SMT_STA_NR == ((int)Enums.ATStatus.Uploaded)) && (!requestIds.Contains(ShpDetail.ID)) ) .ToList(); QuincusResponse.QuincusReponseDataList.ForEach(datalist => { List <Geocode> geocodes = (List <Geocode>)((QuincusReponseData)datalist).geocode; List <ShipmentDataRequest> shipmentDataRequestList = new List <ShipmentDataRequest>(geocodes.Count); foreach (Geocode geocode in geocodes) { ShipmentDataRequest currentShipmentDataRequest = _shipmentDataRequest.FirstOrDefault(_ => _.PKG_NR_TE == geocode.id); ShipmentDataRequest shipmentDataRequest = CreateShipmentAddressUpdateRequest(currentShipmentDataRequest, geocode); shipmentDataRequestList.Add(shipmentDataRequest); // Checking any same address are avaible, If there then updating those address also List <ShipmentDataRequest> sameAddressShpRequest = existingShipmentDetails.Where( (ShipmentDataRequest data) => data.RCV_ADR_TE.ToLower().Replace(" ", "") .Equals(currentShipmentDataRequest.RCV_ADR_TE.ToLower().Replace(" ", "")) ) .ToList(); if (sameAddressShpRequest.Any()) { sameAddressShpRequest.ForEach(shpDetails => { var sameaddressRequest = CreateShipmentAddressUpdateRequest(shpDetails, geocode); shipmentDataRequestList.Add(sameaddressRequest); }); } } shipmentDataRequestList = shipmentDataRequestList.GroupBy(x => x.ID).Select(x => x.First()).ToList(); _shipmentService.UpdateShipmentAddressByIds(shipmentDataRequestList); //we need to update the workflow status int?workflowstatus = _shipmentService.SelectShipmentTotalStatusByWorkflowId(wid); WorkflowDataRequest workflowDataRequest = new WorkflowDataRequest(); workflowDataRequest.ID = wid; workflowDataRequest.WFL_STA_TE = workflowstatus; _workflowService.UpdateWorkflowStatusById(workflowDataRequest); }); } catch (Exception exception) { AuditEventEntry.WriteEntry(exception); } #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(() => iCustomLog.AddLogEntry(new UPS.DataObjects.LogData.LogDataModel() { apiTypes = UPS.DataObjects.LogData.APITypes.QuincusAPI_Translation, apiType = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 4), dateTime = System.DateTime.Now, LogInformation = new UPS.DataObjects.LogData.LogInformation() { LogException = null, LogRequest = quincusTranslatedAddressResponse.QuincusContentRequest, LogResponse = JsonConvert.SerializeObject(QuincusResponse.QuincusReponseDataList) } })); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(Ok(QuincusResponse.QuincusReponseDataList)); } else { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(() => iCustomLog.AddLogEntry(new UPS.DataObjects.LogData.LogDataModel() { apiTypes = UPS.DataObjects.LogData.APITypes.QuincusAPI_Translation, apiType = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 4), dateTime = System.DateTime.Now, LogInformation = new UPS.DataObjects.LogData.LogInformation() { LogException = QuincusResponse.Exception.InnerException.ToString(), LogRequest = quincusTranslatedAddressResponse.QuincusContentRequest, LogResponse = null } })); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(Ok(QuincusResponse.Exception)); } } else { #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed Task.Run(() => iCustomLog.AddLogEntry(new UPS.DataObjects.LogData.LogDataModel() { apiTypes = UPS.DataObjects.LogData.APITypes.QuincusAPI_Translation, apiType = Enum.GetName(typeof(UPS.DataObjects.LogData.APITypes), 4), dateTime = System.DateTime.Now, LogInformation = new UPS.DataObjects.LogData.LogInformation() { LogException = quincusTranslatedAddressResponse.exception.InnerException.ToString(), LogRequest = JsonConvert.SerializeObject(_shipmentDataRequest), LogResponse = null } })); #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed return(Ok(quincusTranslatedAddressResponse.exception)); } } else { return(Ok(quincusTokenDataResponse.exception)); } }
public async Task <ActionResult> GetTranslationAddress([FromBody] List <ShipmentWorkFlowRequest> shipmentWorkFlowRequest) { int wid = 0; decimal requestCount = 0m; if (shipmentWorkFlowRequest.Any()) { wid = shipmentWorkFlowRequest.FirstOrDefault().wfL_ID; } QuincusTranslatedAddressResponse quincusTranslatedAddressResponse = new QuincusTranslatedAddressResponse(); QuincusTokenDataResponse quincusTokenDataResponse = QuincusService.GetToken(new UPS.Quincus.APP.Configuration.QuincusParams() { endpoint = configuration["Quincus:TokenEndPoint"], password = configuration["Quincus:Password"], username = configuration["Quincus:UserName"], }); if (quincusTokenDataResponse.ResponseStatus) { //quincusTranslatedAddressResponse = QuincusService.GetTranslationAddress(new UPS.Quincus.APP.Request.QuincusAddressTranslationRequest() //{ // endpoint = configuration["Quincus:GeoCodeEndPoint"], // shipmentWorkFlowRequests = shipmentWorkFlowRequest, // token = quincusTokenDataResponse.quincusTokenData.token //}); this._quincusAddressTranslationRequest.shipmentWorkFlowRequests = shipmentWorkFlowRequest; this._quincusAddressTranslationRequest.token = quincusTokenDataResponse.quincusTokenData.token; List <List <ShipmentWorkFlowRequest> > shipmentWorkFlowRequests = new List <List <ShipmentWorkFlowRequest> >(); shipmentWorkFlowRequests = QuincusProxy.ChunkBy(shipmentWorkFlowRequest, 20); foreach (List <ShipmentWorkFlowRequest> requests in shipmentWorkFlowRequests) { requestCount = requests.Count(); quincusTranslatedAddressResponse = QuincusService.GetTranslationAddress(this._quincusAddressTranslationRequest); if (quincusTranslatedAddressResponse.Response) { //return Ok(quincusTranslatedAddressResponse.ResponseData); var getAddressTranslation = quincusTranslatedAddressResponse.ResponseData; var QuincusResponse = QuincusService.GetGeoCodeReponseFromQuincus(new UPS.Quincus.APP.Request.QuincusGeoCodeDataRequest() { endpoint = configuration["Quincus:GeoCodeEndPoint"], id = quincusTranslatedAddressResponse.ResponseData.batch_id, quincusTokenData = quincusTokenDataResponse.quincusTokenData }, requestCount); if (QuincusResponse.ResponseStatus) { ShipmentDataRequest shipment = new ShipmentDataRequest(); List <Geocode> geocodes = (List <Geocode>)((QuincusReponseData)QuincusResponse.QuincusReponseData).geocode; List <ShipmentDataRequest> shipmentsDataRequest = new List <ShipmentDataRequest>(geocodes.Count); for (int i = 0; i < geocodes.Count; i++) { ShipmentDataRequest shipmentDataRequest = new ShipmentDataRequest(); shipmentDataRequest.ID = Convert.ToInt32(geocodes[i].id); shipmentDataRequest.WFL_ID = wid; shipmentDataRequest.SHP_ADR_TR_TE = geocodes[i].translated_adddress; shipmentDataRequest.ACY_TE = geocodes[i].accuracy; shipmentDataRequest.CON_NR = geocodes[i].confidence; if ( !string.IsNullOrEmpty(geocodes[i].translated_adddress) //&& geocodes[i].translated_adddress != "NA" //&& !string.Equals(shipmentWorkFlowRequest.Where(s => s.id == shipmentDataRequest.ID).FirstOrDefault().rcV_ADR_TE.Trim(), // geocodes[i].translated_adddress.Trim()) ) { shipmentDataRequest.SMT_STA_NR = ((int)Enums.ATStatus.Translated); shipmentDataRequest.SMT_STA_TE = "Translated"; } else { shipmentDataRequest.SMT_STA_NR = Convert.ToInt32(shipmentWorkFlowRequest.Where(s => s.id == shipmentDataRequest.ID).FirstOrDefault().smT_STA_NR); shipmentDataRequest.SMT_STA_TE = Convert.ToString(shipmentWorkFlowRequest.Where(s => s.id == shipmentDataRequest.ID).FirstOrDefault().smT_STA_TE); } shipmentsDataRequest.Add(shipmentDataRequest); } ShipmentService shipmentService = new ShipmentService(); shipmentService.UpdateShipmentAddressByIds(shipmentsDataRequest); _workflowID = shipmentsDataRequest.FirstOrDefault().WFL_ID; //we need to update the workflow status int?workflowstatus = shipmentService.SelectShipmentTotalStatusByWorkflowId(_workflowID); WorkflowDataRequest workflowDataRequest = new WorkflowDataRequest(); workflowDataRequest.ID = _workflowID; workflowDataRequest.WFL_STA_TE = workflowstatus; workflowService.UpdateWorkflowStatusById(workflowDataRequest); } else { if (QuincusResponse.Exception == null) { AuditEventEntry.WriteEntry(new Exception("Translation failed...")); } else { AuditEventEntry.WriteEntry(new Exception(QuincusResponse.Exception.ToString())); } return(Ok(QuincusResponse?.Exception)); } } else { if (quincusTranslatedAddressResponse.exception == null) { AuditEventEntry.WriteEntry(new Exception("Translation failed...")); } else { AuditEventEntry.WriteEntry(new Exception(quincusTranslatedAddressResponse.exception.ToString())); } return(Ok(quincusTranslatedAddressResponse?.exception)); } } return(Ok(quincusTranslatedAddressResponse.ResponseData)); } else { if (quincusTokenDataResponse.exception == null) { AuditEventEntry.WriteEntry(new Exception("Translation failed...")); } else { AuditEventEntry.WriteEntry(new Exception(quincusTokenDataResponse.exception.ToString())); } return(Ok(quincusTokenDataResponse?.exception)); } }