Esempio n. 1
0
 public IActionResult DeleteLoad([FromBody] LoadDetailViewModel load)
 {
     try
     {
         var loadData = _mapper.Map <LoadDetailData>(load);
         var result   = _loadService.DeleteLoad(loadData, customerId: _user.UserId.Value, username: _systemUser);
         return(Success(_mapper.Map <LoadDetailViewModel>(result)));
     }
     catch (ValidationException e)
     {
         return(Error <LoadDetailViewModel>(e));
     }
 }
Esempio n. 2
0
        public async Task <IActionResult> UpdateLoad([FromBody] LoadDetailViewModel load, [FromQuery] UpdateLoadOptionsViewModel options)
        {
            try
            {
                /**
                 * DO NOT YET consider auto-posting via the v2 customer API
                 * [10:08 AM] Kind, Brian K.
                 *     Now I am questioning the true purpose of Auto Post To Marketplace.  Based on what you just gave me I am thinking the Auto Post to Marketplace was really for  the old way.
                 * ​[10:08 AM] Vetta, Joe (Consultant)
                 *     (laugh)
                 * ​[10:11 AM] Kind, Brian K.
                 *     How far are we in the rabbit hole are we in fixing the bug?  Can we leave the new way logic alone.  Knowing my scenario #2  is just the way it is for now.
                 * ​[10:11 AM] Vetta, Joe (Consultant)
                 *     Yes, it's a simple thing for me to undo
                 * ​[10:11 AM] Kind, Brian K.
                 *     So original issue was EDI (Old Way), shipper had Auto Post to marketplace set to 'N'.  We fixed it.
                 * ​[10:12 AM] Kind, Brian K.
                 *     I can reach out to Kevin and explain.  So basically new way does not care about Auto Post to marketplace for now.
                 * ​[10:13 AM] Kind, Brian K.
                 *     Old way will
                 */
                var loadData = _mapper.Map <LoadDetailData>(load);
                loadData.LoadTransaction = new LoadTransactionData()
                {
                    TransactionType = TransactionTypeData.PendingUpdate
                };
                var updateOptions = new UpdateLoadOptions()
                {
                    MapObject                 = true,
                    ValidateAddress           = true,
                    ManuallyCreated           = false,
                    UpdateSpecialInstructions = false,
                    AppendComments            = options?.AppendComments ?? false
                };

                var result         = _loadService.GenerateReturnURL(new LoadDetailData[] { loadData });
                var updateResponse = await _loadService.UpdateLoad(loadData, _user.UserId.Value, _systemUser, updateOptions);

                if (!updateResponse.IsSuccess)
                {
                    return(BadRequest(new ResponseMessage <string>(), updateResponse.ModelState));
                }

                return(Success(result));
            }
            catch (ValidationException e)
            {
                return(Error <string>(e));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> GetById(Guid id)
        {
            try
            {
                var load = await _loadService.GetLoadByIdAsync(id, _userContext.UserId.Value);

                LoadDetailViewModel result = _mapper.Map <LoadDetailViewModel>(load);
                result.ViewOnly = await this._userProfileService.IsViewOnlyUserAsync(_userContext.UserId.Value);

                return(Success(result));
            }
            catch (UnauthorizedAccessException ex)
            {
                return(Forbidden <ResponseMessage <LoadDetailViewModel> >(ex));
            }
        }
Esempio n. 4
0
        public IActionResult AcceptLoad([FromBody] LoadDetailViewModel load)
        {
            try
            {
                var loadData = _mapper.Map <LoadDetailData>(load);
                loadData.LoadTransaction = new LoadTransactionData()
                {
                    TransactionType = TransactionTypeData.Accepted
                };

                var result = _loadService.AcceptLoad(loadData, customerId: _user.UserId.Value, username: _systemUser);
                return(Success(_mapper.Map <LoadDetailViewModel>(result)));
            }
            catch (ValidationException e)
            {
                return(Error <LoadDetailViewModel>(e));
            }
        }
Esempio n. 5
0
        public async Task <IActionResult> PreviewUpdateLoad([FromBody] LoadDetailViewModel load)
        {
            try
            {
                var loadData = _mapper.Map <LoadDetailData>(load);
                loadData.LoadTransaction = new LoadTransactionData()
                {
                    TransactionType = TransactionTypeData.Updated
                };
                var updateOptions = new UpdateLoadOptions()
                {
                    MapObject                 = true,
                    ManuallyCreated           = false,
                    UpdateSpecialInstructions = false,
                    AppendComments            = true,  // overlay any comments
                    SaveChanges               = false, // ensure we don't apply the updates
                    IgnoreFuel                = true,
                    IgnoreLineHaulRate        = true,
                    AddSmartSpot              = false
                };

                var result = await _loadService.PreviewUpdateLoad(loadData, _user.UserId.Value, _systemUser, updateOptions);

                if (string.IsNullOrEmpty(result.ErrorMessage))
                {
                    return(Success(new CheckUpdateLoadStatusViewModel()
                    {
                        CanLoadRemainInLoadshop = result.LoadKeptInMarketplace
                    }));
                }

                throw new ValidationException(result.ErrorMessage);
            }
            catch (ValidationException e)
            {
                return(Error <LoadDetailViewModel>(e));
            }
        }
Esempio n. 6
0
        public async Task <IActionResult> RemoveLoad([FromBody] LoadDetailViewModel load)
        {
            try
            {
                var loadData = _mapper.Map <LoadDetailData>(load);
                loadData.LoadTransaction = new LoadTransactionData()
                {
                    TransactionType = TransactionTypeData.Removed
                };

                var removeResponse = await _loadService.UpdateLoad(loadData, _user.UserId.Value, _systemUser, new UpdateLoadOptions());

                if (!removeResponse.IsSuccess)
                {
                    return(BadRequest(new ResponseMessage <string>(), removeResponse.ModelState));
                }
                return(Success(_mapper.Map <LoadDetailViewModel>(removeResponse.Data)));
            }
            catch (ValidationException e)
            {
                return(Error <LoadDetailViewModel>(e));
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> RemoveLoad([FromBody] LoadDetailViewModel load)
        {
            try
            {
                var loadData = _mapper.Map <LoadDetailData>(load);
                loadData.LoadTransaction = new LoadTransactionData()
                {
                    TransactionType = TransactionTypeData.Removed
                };

                var result = await _loadService.UpdateLoad(loadData, customerId : _user.UserId.Value, username : _systemUser, new UpdateLoadOptions());

                if (result.IsSuccess)
                {
                    return(Success(_mapper.Map <LoadDetailViewModel>(result.Data)));
                }

                throw new ValidationException(result.GetAllMessages());
            }
            catch (ValidationException e)
            {
                return(Error <LoadDetailViewModel>(e));
            }
        }
Esempio n. 8
0
        public async Task <IActionResult> UpdateLoad([FromBody] LoadDetailViewModel load, [FromQuery] bool ignoreFuel = false,
                                                     [FromQuery] bool ignoreLineHaulRate = false, [FromQuery] bool useSmartSpotPricing = false)
        {
            try
            {
                var loadData = _mapper.Map <LoadDetailData>(load);

                var custIdentUserId = _user.UserId.Value;
                var autoPost        = load.AutoPostLoad ?? _loadService.GetAutoPostToLoadshop(custIdentUserId);

                /**
                 * Normal V1 behavior is to set the load to Updated, which means the load shows up on the Marketplace
                 * immedaitely.  For some reason TRS_Loadshop_LoadshopIntegrationService still calls this v1 end-point
                 * when updating loads, even though we don't normally want loads to go directly to the marketplace,
                 * now that shippers have a Post tab to work with directly in Loadshop.
                 *
                 * That means, we need to check the Shipper Profile before we update the load with an Updated transaction.
                 * If the shipper's profile says to not auto post the load, then we should update the load with a
                 * Pending Update transaction, which keeps the load on the Shipper's Post tab, and does not show it on the
                 * Marketplace tab.
                 *
                 * The V2 UpdateLoad end-point automatically sets loads to Pending Update, so I'm not entirely sure why
                 * we're still calling V1, so we may have to revist this and/or retire this end-point at some future date.
                 */
                if (autoPost)
                {
                    loadData.LoadTransaction = new LoadTransactionData
                    {
                        TransactionType = TransactionTypeData.Updated
                    };

                    /**
                     * Even when the shipper profile says the load should AutoPost, we do not
                     * allow that if the load does not have a line haul rate and the TOPS
                     * LoadshopShipperMapping is set to not use SmartSpot pricing.
                     */
                    if (loadData.LineHaulRate == 0m && !useSmartSpotPricing)
                    {
                        loadData.LoadTransaction = new LoadTransactionData
                        {
                            TransactionType = TransactionTypeData.PendingUpdate
                        };
                    }
                }
                else
                {
                    loadData.LoadTransaction = new LoadTransactionData
                    {
                        TransactionType = TransactionTypeData.PendingUpdate
                    };
                }

                var updateOptions = new UpdateLoadOptions()
                {
                    MapObject                     = true,
                    ManuallyCreated               = false,
                    UpdateSpecialInstructions     = false,
                    AppendComments                = false,
                    IgnoreLineHaulRate            = ignoreLineHaulRate,
                    IgnoreFuel                    = ignoreFuel,
                    AddSmartSpot                  = useSmartSpotPricing,
                    OverrideLineHaulWithSmartSpot = useSmartSpotPricing
                };

                var result = await _loadService.UpdateLoad(loadData, _user.UserId.Value, _systemUser, updateOptions);

                if (result.IsSuccess)
                {
                    return(Success(_mapper.Map <LoadDetailViewModel>(result.Data)));
                }

                throw new ValidationException(result.GetAllMessages());
            }
            catch (ValidationException e)
            {
                return(Error <LoadDetailViewModel>(e));
            }
        }
Esempio n. 9
0
        public async Task <IActionResult> CreateLoad([FromBody] LoadDetailViewModel load, [FromQuery] bool useSmartSpotPricing = false)
        {
            try
            {
                var loadData        = _mapper.Map <LoadDetailData>(load);
                var custIdentUserId = _user.UserId.Value;
                var autoPost        = load.AutoPostLoad ?? _loadService.GetAutoPostToLoadshop(custIdentUserId);

                if (autoPost)
                {
                    loadData.LoadTransaction = new LoadTransactionData
                    {
                        TransactionType = TransactionTypeData.New
                    };

                    /**
                     * Even when the shipper profile says the load should AutoPost, we do not
                     * allow that if the load does not have a line haul rate and the TOPS
                     * LoadshopShipperMapping is set to not use SmartSpot pricing.
                     * Also, do not allow the load to auto post if the load uses a Fuel Rate
                     * set by the customer and Fuel Rate is 0.
                     */
                    if ((loadData.LineHaulRate == 0m && !useSmartSpotPricing) ||
                        (load.UseCustomerFuel && load.FuelRate == 0m))
                    {
                        loadData.LoadTransaction = new LoadTransactionData
                        {
                            TransactionType = TransactionTypeData.PendingAdd
                        };
                    }
                }
                else
                {
                    loadData.LoadTransaction = new LoadTransactionData
                    {
                        TransactionType = TransactionTypeData.PendingAdd
                    };
                }

                var options = new CreateLoadOptionsDto()
                {
                    ManuallyCreated               = false,
                    AddSpecialInstructions        = true,
                    AddSmartSpot                  = useSmartSpotPricing,
                    OverrideLineHaulWithSmartSpot = useSmartSpotPricing
                };

                var response = await _loadService.CreateLoad(loadData, customerId : _user.UserId.Value, username : _systemUser, options);

                if (response.IsSuccess)
                {
                    return(Success(_mapper.Map <LoadDetailViewModel>(response.Data)));
                }

                throw new ValidationException(response.GetAllMessages());
            }
            catch (ValidationException e)
            {
                return(Error <LoadDetailViewModel>(e));
            }
        }