public async Task <IActionResult> CreateLoad([FromBody] LoadDetailViewModel load) { try { var loadData = _mapper.Map <LoadDetailData>(load); /** * 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 */ loadData.LoadTransaction = new LoadTransactionData() { TransactionType = TransactionTypeData.PendingAdd }; var result = _loadService.GenerateReturnURL(new LoadDetailData[] { loadData }); var options = new CreateLoadOptionsDto() { ValidateAddress = OrderAddressValidationEnum.Validate, ManuallyCreated = false }; var createResponse = await _loadService.CreateLoad(loadData, customerId : _user.UserId.Value, username : _systemUser, options); if (!createResponse.IsSuccess) { return(BadRequest(new ResponseMessage <string>(), createResponse.ModelState)); } return(Success(result)); } catch (ValidationException e) { return(Error <string>(e)); } }
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)); } }
public async Task <IActionResult> CreateLoad([FromBody] OrderEntryViewModel orderEntryVM) { try { if (!_userContext.UserId.HasValue) { throw new Exception("Invalid UserId"); } // LoadService.CreateLoad expects the Customer.IdentUserId, not the Customer.CustomerId var customerIdentUserId = await _userProfileService.GetPrimaryCustomerIdentUserId(_userContext.UserId.Value); if (!customerIdentUserId.HasValue) { throw new Exception("User does not have a primary customer."); } // Saving locations requires FK to CustomerID var customerId = await _userProfileService.GetPrimaryCustomerId(_userContext.UserId.Value); if (!customerId.HasValue) { throw new Exception("User does not have a primary customer."); } /** * The UI allows entering an Order Number, which is effectively the ReferenceLoadDisplay, so in order * to generate a ReferenceLoadId, we need to get the user's primary customer's TOPS Owner ID and then * prepend that to the ReferenceLoadDisplay to get the ReferenceLoadId */ var customerOwnerId = await _userProfileService.GetPrimaryCustomerOwner(_userContext.UserId.Value); orderEntryVM.ReferenceLoadId = CalculateReferenceLoadId(customerOwnerId, orderEntryVM.ReferenceLoadDisplay); SetLoadStopDtTms(orderEntryVM); var load = _mapper.Map <LoadDetailData>(orderEntryVM); load.LoadTransaction = new LoadTransactionData() { TransactionType = TransactionTypeData.PendingAdd }; /** * LoadStop.ApptType is a calculated field, so the logic for doing so and setting its value on * all load stops is kept in the LoadService. We call it here to update the values before calling * the shared CreateLoad code, so the load stops will pass validation */ load.LoadStops = _loadService.SetApptTypeOnLoadStops(load.LoadStops); var options = new CreateLoadOptionsDto() { ValidateAddress = OrderAddressValidationEnum.Validate, ManuallyCreated = true }; var createResponse = await _loadService.CreateLoad(load, customerIdentUserId.Value, _userContext.UserName, options); if (!createResponse.IsSuccess) { var problemDetails = new ValidationProblemDetails(createResponse.ModelState) { Title = "Create Load Error", Detail = "One or more errors occurred when trying to save this load. See form for error details", Status = (int)HttpStatusCode.BadRequest, Instance = $"urn:kbxl:error:{Guid.NewGuid()}" }; return(BadRequest(problemDetails)); } else { SaveLocations(customerId.Value, load.LoadStops); } return(Success(orderEntryVM)); } catch (ValidationException exception) { return(Error <List <LocationViewModel> >(exception)); } }