public async Task <IActionResult> GetLoadsBySearchType(ShipperSearchTypeData searchType, [FromBody] LoadSearchCriteria loadSearchCriteria)
        {
            try
            {
                if (!_userContext.UserId.HasValue)
                {
                    throw new EmptyUserIdException("Invalid UserId");
                }

                var pageableQuery = _shippingService.GetLoadsBySearchType(searchType);

                if (loadSearchCriteria != null)
                {
                    pageableQuery.Filter(DomainServices.Utilities.QueryFilters.GetShippingLoadFilter(loadSearchCriteria));
                }

                var response = await pageableQuery
                               .HandleSorting(Request)
                               .HandlePaging(Request)
                               .ToPageableResponse();

                return(Success(response));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Пример #2
0
        public string[] MapShipperSearchTypeToTransactionList(ShipperSearchTypeData searchType)
        {
            string[] transactionTypeIds;

            switch (searchType)
            {
            // "All", excluding Removed
            case ShipperSearchTypeData.All:
            {
                transactionTypeIds = new string[] {
                    TransactionTypes.Posted,
                    TransactionTypes.PendingFuel,
                    TransactionTypes.PendingRates,
                    TransactionTypes.New,
                    TransactionTypes.Updated,
                    TransactionTypes.PendingUpdate,
                    TransactionTypes.PreTender,
                    TransactionTypes.Pending,
                    TransactionTypes.SentToShipperTender,
                    TransactionTypes.Accepted,
                    TransactionTypes.Delivered,
                    TransactionTypes.PendingRemoveScac
                };
                break;
            }

            case ShipperSearchTypeData.PendingAdd:
            {
                transactionTypeIds = new string[] { TransactionTypes.PendingAdd, TransactionTypes.PendingUpdate };
                break;
            }

            case ShipperSearchTypeData.Posted:
            {
                transactionTypeIds = new string[] { TransactionTypes.Posted, TransactionTypes.PendingFuel, TransactionTypes.PendingRates, TransactionTypes.New, TransactionTypes.Updated };
                break;
            }

            case ShipperSearchTypeData.Booked:
            {
                transactionTypeIds = new string[] { TransactionTypes.PreTender, TransactionTypes.Pending, TransactionTypes.SentToShipperTender, TransactionTypes.Accepted };
                break;
            }

            case ShipperSearchTypeData.Delivered:
            {
                transactionTypeIds = new string[] { TransactionTypes.Delivered };
                break;
            }

            default:
                throw new Exception("ShipperSearchType not valid");
            }

            return(transactionTypeIds);
        }
Пример #3
0
        public List <ShippingLoadViewData> GetLoadsBySearchType_Delete(ShipperSearchTypeData searchType)
        {
            var userPrimaryCustomerId = _context.Users.SingleOrDefault(u => u.IdentUserId == _userContext.UserId)?.PrimaryCustomerId;

            if (userPrimaryCustomerId.HasValue)
            {
                return(GetLoadsBySearchType(searchType, max: int.MaxValue).ToList());
            }

            return(new List <ShippingLoadViewData>());
        }
Пример #4
0
        private string MapSearchTypeToTransactionList(ShipperSearchTypeData searchType)
        {
            var transactionTypeIds = _serviceUtilities.MapShipperSearchTypeToTransactionList(searchType);

            return(string.Join(",", transactionTypeIds));
        }
Пример #5
0
        protected PageableQuery <ShippingLoadViewData> GetLoadsBySearchType(ShipperSearchTypeData searchType, int max, DateTime?visibilityPickupWindowDate = null, bool topsToGoCarrier = false, bool p44Carrier = false)
        {
            var userPrimaryCustomerId       = _context.Users.SingleOrDefault(u => u.IdentUserId == _userContext.UserId)?.PrimaryCustomerId;
            var onLoadShopTransactionTypes  = new[] { "New", "Updated" };
            var bookedUserTransActionsTypes = new[] { "Accepted", "Pending" };
            var currentDate   = _dateTime.Now;
            var isMarketplace = ShipperSearchTypeData.Posted == searchType;

            visibilityPickupWindowDate = visibilityPickupWindowDate ?? currentDate;

            if (userPrimaryCustomerId.HasValue)
            {
                //var transactionTypeIds = MapSearchTypeToTransactionList(c);
                //var shippingLoads = _context.ShippingLoadViews.FromSql($"EXECUTE spGetLoadsByShipperAndTranType @CustomerId = {userPrimaryCustomerId}, @TransactionTypes = {transactionTypeIds}");

                var transTypes = _serviceUtilities.MapShipperSearchTypeToTransactionList(searchType);

                if (isMarketplace)
                {
                    return((from l in _context.Loads
                            join c in _context.Customers on l.CustomerId equals c.CustomerId
                            join OriginLoadStop in _context.LoadStops.Where(ls => ls.StopNbr == 1) on l.LoadId equals OriginLoadStop.LoadId
                            join DestinationLoadStop in _context.LoadStops on new { l.LoadId, StopNbr = (int)l.Stops } equals new { DestinationLoadStop.LoadId, DestinationLoadStop.StopNbr }
                            where
                            transTypes.Contains(l.LatestTransactionTypeId) &&
                            l.CustomerId == userPrimaryCustomerId
                            select new ShippingLoadViewData()
                    {
                        LoadId = l.LoadId,
                        CustomerId = l.CustomerId,
                        ReferenceLoadId = l.ReferenceLoadId,
                        ReferenceLoadDisplay = l.ReferenceLoadDisplay,
                        Stops = l.Stops,
                        Miles = l.Miles,
                        LineHaulRate = l.LineHaulRate,
                        SmartSpotRate = l.SmartSpotRate,
                        FuelRate = l.FuelRate,
                        Commodity = l.Commodity,
                        Weight = l.Weight,
                        IsHazMat = l.IsHazMat,
                        TransactionTypeId = l.LatestTransactionTypeId,
                        DistanceFromOrig = 0,
                        DistanceFromDest = 0,
                        Onloadshop = onLoadShopTransactionTypes.Contains(l.LatestTransactionTypeId),
                        CustomerLoadTypeId = l.CustomerLoadTypeId,

                        //Equipment
                        EquipmentId = l.EquipmentId,
                        EquipmentType = l.Equipment.EquipmentDesc,
                        EquipmentCategoryId = l.Equipment.CategoryId ?? "Unknown",
                        EquipmentCategoryDesc = l.Equipment.CategoryEquipmentDesc,
                        EquipmentTypeDisplay = l.Equipment.CategoryId == null ? l.Equipment.EquipmentDesc : l.Equipment.CategoryEquipmentDesc,

                        OriginLat = (double)OriginLoadStop.Latitude,
                        OriginLng = (double)OriginLoadStop.Longitude,
                        OriginCity = OriginLoadStop.City,
                        OriginState = OriginLoadStop.State,
                        OriginEarlyDtTm = OriginLoadStop.EarlyDtTm,
                        OriginLateDtTm = OriginLoadStop.LateDtTm,
                        DestLat = (double)DestinationLoadStop.Latitude,
                        DestLng = (double)DestinationLoadStop.Longitude,
                        DestCity = DestinationLoadStop.City,
                        DestState = DestinationLoadStop.State,
                        DestEarlyDtTm = DestinationLoadStop.EarlyDtTm,
                        DestLateDtTm = DestinationLoadStop.LateDtTm,
                        IsEstimatedFSC = FscUtilities.IsEstimatedFsc(c, (OriginLoadStop.EarlyDtTm ?? OriginLoadStop.LateDtTm), _dateTime.Now),
                        //Needed so the quick filter works
                        Scac = null,
                        // Load entire entity to prevent EF from doing a subselect
                        LoadServiceTypes = l.LoadServiceTypes
                    })
                           .OrderByDescending(l => l.OriginLateDtTm)
                           .ToPageableQuery(shippingLoadList =>
                    {
                        foreach (var l in shippingLoadList)
                        {
                            l.ShowVisibilityWarning =
                                l.OriginLateDtTm > currentDate &&
                                l.OriginLateDtTm <= visibilityPickupWindowDate &&
                                l.DestLateDtTm >= currentDate &&
                                ((topsToGoCarrier && p44Carrier && l.VisibilityPhoneNumber == null && !l.MobileExternallyEntered && l.VisibilityTruckNumber == null) ||
                                 (topsToGoCarrier && !p44Carrier && l.VisibilityPhoneNumber == null && !l.MobileExternallyEntered) ||
                                 (!topsToGoCarrier && p44Carrier && l.VisibilityTruckNumber == null));
                        }
                        return Task.CompletedTask;
                    }, max));
                }
                else
                {
                    return((from l in _context.Loads
                            join c in _context.Customers on l.CustomerId equals c.CustomerId
                            join lt in _context.LoadTransactions on l.LoadId equals lt.LoadId
                            join lc in _context.LoadClaims on lt.LoadTransactionId equals lc.LoadTransactionId into lcJoin
                            from lc in lcJoin.DefaultIfEmpty()
                            join claimUser in _context.Users on lc.UserId equals claimUser.UserId into claimUserJoin
                            from claimUser in claimUserJoin.DefaultIfEmpty()
                            join claimScac in _context.CarrierScacs on lc.Scac equals claimScac.Scac into claimScacJoin
                            from claimScac in claimScacJoin.DefaultIfEmpty()
                            join claimCarrier in _context.Carriers on claimScac.CarrierId equals claimCarrier.CarrierId into claimCarrierJoin
                            from claimCarrier in claimCarrierJoin.DefaultIfEmpty()
                            join OriginLoadStop in _context.LoadStops.Where(ls => ls.StopNbr == 1) on l.LoadId equals OriginLoadStop.LoadId
                            join DestinationLoadStop in _context.LoadStops on new { l.LoadId, StopNbr = (int)l.Stops } equals new { DestinationLoadStop.LoadId, DestinationLoadStop.StopNbr }
                            where
                            transTypes.Contains(l.LatestTransactionTypeId) &&
                            l.CustomerId == userPrimaryCustomerId &&
                            (lc.LoadClaimId == (from lt in _context.LoadTransactions
                                                join lc in _context.LoadClaims on lt.LoadTransactionId equals lc.LoadTransactionId
                                                where lt.LoadId == l.LoadId
                                                orderby lc.CreateDtTm descending
                                                select lc).FirstOrDefault().LoadClaimId)
                            select new ShippingLoadViewData()
                    {
                        LoadId = l.LoadId,
                        CustomerId = l.CustomerId,
                        ReferenceLoadId = l.ReferenceLoadId,
                        ReferenceLoadDisplay = l.ReferenceLoadDisplay,
                        Stops = l.Stops,
                        Miles = l.Miles,
                        LineHaulRate = lc != null ? lc.LineHaulRate : l.LineHaulRate,
                        SmartSpotRate = l.SmartSpotRate,
                        FuelRate = l.FuelRate,
                        Commodity = l.Commodity,
                        Weight = l.Weight,
                        IsHazMat = l.IsHazMat,
                        TransactionTypeId = l.LatestTransactionTypeId,
                        DistanceFromOrig = 0,
                        DistanceFromDest = 0,
                        Onloadshop = onLoadShopTransactionTypes.Contains(l.LatestTransactionTypeId),
                        CustomerLoadTypeId = l.CustomerLoadTypeId,

                        //Equipment
                        EquipmentId = l.EquipmentId,
                        EquipmentType = l.Equipment.EquipmentDesc,
                        EquipmentCategoryId = l.Equipment.CategoryId ?? "Unknown",
                        EquipmentCategoryDesc = l.Equipment.CategoryEquipmentDesc,
                        EquipmentTypeDisplay = l.Equipment.CategoryId == null ? l.Equipment.EquipmentDesc : l.Equipment.CategoryEquipmentDesc,

                        OriginLat = (double)OriginLoadStop.Latitude,
                        OriginLng = (double)OriginLoadStop.Longitude,
                        OriginCity = OriginLoadStop.City,
                        OriginState = OriginLoadStop.State,
                        OriginEarlyDtTm = OriginLoadStop.EarlyDtTm,
                        OriginLateDtTm = OriginLoadStop.LateDtTm,
                        DestLat = (double)DestinationLoadStop.Latitude,
                        DestLng = (double)DestinationLoadStop.Longitude,
                        DestCity = DestinationLoadStop.City,
                        DestState = DestinationLoadStop.State,
                        DestEarlyDtTm = DestinationLoadStop.EarlyDtTm,
                        DestLateDtTm = DestinationLoadStop.LateDtTm,
                        IsEstimatedFSC = FscUtilities.IsEstimatedFsc(c, (OriginLoadStop.EarlyDtTm ?? OriginLoadStop.LateDtTm), _dateTime.Now),

                        //Load Claim
                        Scac = lc.Scac,
                        BookedUser = claimUser.Username,
                        BookedUserCarrierName = claimCarrier.CarrierName,
                        BillingLoadId = lc.BillingLoadId,
                        BillingLoadDisplay = lc.BillingLoadDisplay,
                        VisibilityPhoneNumber = lc.VisibilityPhoneNumber,
                        VisibilityTruckNumber = lc.VisibilityTruckNumber,
                        VisibilityChgDtTm = lc.VisibilityChgDtTm,
                        MobileExternallyEntered = lc.MobileExternallyEntered,
                        // Load entire entity to prevent EF from doing a subselect
                        LoadServiceTypes = l.LoadServiceTypes
                    })
                           .OrderByDescending(l => l.OriginLateDtTm)
                           .ToPageableQuery(shippingLoadList =>
                    {
                        foreach (var l in shippingLoadList)
                        {
                            l.ShowVisibilityWarning =
                                l.OriginLateDtTm > currentDate &&
                                l.OriginLateDtTm <= visibilityPickupWindowDate &&
                                l.DestLateDtTm >= currentDate &&
                                ((topsToGoCarrier && p44Carrier && l.VisibilityPhoneNumber == null && !l.MobileExternallyEntered && l.VisibilityTruckNumber == null) ||
                                 (topsToGoCarrier && !p44Carrier && l.VisibilityPhoneNumber == null && !l.MobileExternallyEntered) ||
                                 (!topsToGoCarrier && p44Carrier && l.VisibilityTruckNumber == null));
                        }
                        return Task.CompletedTask;
                    }, max));
                }
            }

            return(PageableQuery <ShippingLoadViewData> .Empty());
        }
Пример #6
0
 public PageableQuery <ShippingLoadViewData> GetLoadsBySearchType(ShipperSearchTypeData searchType, DateTime?visibilityPickupWindowDate = null, bool topsToGoCarrier = false, bool p44Carrier = false)
 {
     return(GetLoadsBySearchType(searchType, 100, visibilityPickupWindowDate, topsToGoCarrier, p44Carrier));
 }
 public async Task <IActionResult> GetLoadsBySearchType(ShipperSearchTypeData searchType)
 {
     return(await GetLoadsBySearchType(searchType, null));
 }