Exemplo n.º 1
0
        private async Task <(int, int)> GetMileage(LoadshopSmartSpotQuoteRequest request)
        {
            var mileageRequest = new MileageRequestData
            {
                OriginCity       = request.OriginCity,
                OriginState      = request.OriginState,
                OriginPostalCode = request.OriginPostalCode,
                OriginCountry    = request.OriginCountry,

                DestinationCity       = request.DestinationCity,
                DestinationState      = request.DestinationState,
                DestinationPostalCode = request.DestinationPostalCode,
                DestinationCountry    = request.DestinationCountry
            };

            var routeMiles = await _mileageService.GetDirectRouteMiles(mileageRequest);

            var directMiles = _mileageService.GetDirectMiles(mileageRequest);

            if (directMiles <= 0)
            {
                directMiles = routeMiles;
            }
            return(routeMiles, directMiles);
        }
Exemplo n.º 2
0
        private void AssertRequest(LoadshopSmartSpotQuoteRequest request, BaseServiceResponse response)
        {
            if (request == null)
            {
                throw new ValidationException($"{ERROR_TYPE}: Request is required");
            }

            if (string.IsNullOrWhiteSpace(request.EquipmentId))
            {
                response.AddError($"urn:root:{nameof(request.EquipmentId)}", "Equipment is required");
            }

            if (request.Weight == null || request.Weight <= 0)
            {
                response.AddError($"urn:root:{nameof(request.Weight)}", "Weight is required");
            }

            if (request.PickupDate == null || request.PickupDate.Equals(DateTimeOffset.MinValue))
            {
                response.AddError($"urn:root:{nameof(request.PickupDate)}", "Date is required");
            }

            if (string.IsNullOrWhiteSpace(request.OriginPostalCode))
            {
                response.AddError($"urn:root:{nameof(request.OriginPostalCode)}", "Origin Postal Code is required");
            }
            else if (string.IsNullOrWhiteSpace(request.OriginState))
            {
                response.AddError($"urn:root:{nameof(request.OriginState)}", "Origin State is required");
            }
            else if (string.IsNullOrWhiteSpace(request.OriginCountry))
            {
                response.AddError($"urn:root:{nameof(request.OriginCountry)}", "Origin Country is required");
            }

            if (string.IsNullOrWhiteSpace(request.DestinationPostalCode))
            {
                response.AddError($"urn:root:{nameof(request.DestinationPostalCode)}", "Destination Postal Code is required");
            }
            else if (string.IsNullOrWhiteSpace(request.DestinationState))
            {
                response.AddError($"urn:root:{nameof(request.DestinationState)}", "Destination State is required");
            }
            else if (string.IsNullOrWhiteSpace(request.DestinationCountry))
            {
                response.AddError($"urn:root:{nameof(request.DestinationCountry)}", "Destination Country is required");
            }
        }
Exemplo n.º 3
0
        private async Task <AWSSmartSpotPriceRequest> MapFromLoadshopSmartSpotQuoteRequest(LoadshopSmartSpotQuoteRequest request, BaseServiceResponse response)
        {
            AssertRequest(request, response);
            if (!response.IsSuccess)
            {
                return(null);
            }

            var(routeMiles, directMiles) = await GetMileage(request);

            var carriers          = (await _securityService.GetContractedCarriersByPrimaryCustomerIdAsync());
            var carrierCount      = carriers?.Count() ?? 1;
            var distinctScacCount = carriers?.SelectMany(_ => _.CarrierScacs).Distinct().Count() ?? 1;


            var aws = new AWSSmartSpotPriceRequest();

            aws.LoadId            = Guid.Empty;
            aws.TransactionCreate = DateTime.Now;
            aws.TransactionTypeId = "New";
            aws.LoadShopMiles     = routeMiles;
            aws.DirectMiles       = directMiles;
            aws.Stops             = 2;
            aws.Weight            = request.Weight.Value;
            aws.Commodity         = "Misc/Other";
            aws.EquipmentId       = request.EquipmentId;
            aws.PkupDate          = request.PickupDate.Value.Date;
            aws.OrigState         = request.OriginState;
            aws.O3Zip             = request.OriginPostalCode.Length >= 3 ? request.OriginPostalCode.Substring(0, 3) : null;
            aws.DestState         = request.DestinationState;
            aws.D3Zip             = request.DestinationPostalCode.Length >= 3 ? request.DestinationPostalCode.Substring(0, 3) : null;

            aws.NbrSCACsRequest        = distinctScacCount;
            aws.NbrCarriersRequest     = carrierCount;
            aws.NbrSCACsPosted         = 0;
            aws.NbrContractSCACsPosted = 0;
            aws.NbrSCACsHidden         = 0;

            return(aws);
        }