public void TestGetOpCoStockWarehouseCodes() { using (TransactionScope ts = new TransactionScope()) { // Populate and Create an OpCo Shipment with default values OpCoShipment opCoShipment = OpcoShipmentTests.PopulateNewItem(); OpCoShipmentController.SaveShipment(opCoShipment); // Save the OpCo Code string SaveOpCoCode = opCoShipment.OpCoCode; // Create a second OpCo Shipment with the same OpCo Code, but a different stock warehouse code opCoShipment.Id = -1; opCoShipment.OpCoCode = SaveOpCoCode; opCoShipment.StockWarehouseCode = "ZZZ"; opCoShipment.ShipmentNumber = "Ship2"; opCoShipment.DespatchNumber = "Despatch2"; OpCoShipmentController.SaveShipment(opCoShipment); List <Warehouse> warehouseList = WarehouseController.GetOpCoStockWarehouseCodes(SaveOpCoCode); Assert.IsTrue(warehouseList.Count == 2); } }
static internal TDCShipment PopulateItem() { TDCShipment tdcShipment = new TDCShipment(); OpCoShipment opCoShipment = OpcoShipmentTests.PopulateNewItem(); try { tdcShipment.OpCoShipmentId = OpCoShipmentController.SaveShipment(opCoShipment); } catch (InValidBusinessObjectException e) { Console.Write(e.ValidatableObject.ValidationMessages); } tdcShipment.OpCoCode = opCoShipment.OpCoCode; tdcShipment.OpCoSequenceNumber = 1; tdcShipment.OpCoContact.Email = "Email"; tdcShipment.OpCoContact.Name = "Name"; tdcShipment.DespatchNumber = "Number"; tdcShipment.RequiredShipmentDate = DateTime.Now; tdcShipment.CustomerNumber = "CustNo"; tdcShipment.CustomerName = "CustomerName"; tdcShipment.CustomerReference = "ref"; tdcShipment.CustomerAddress.Line1 = "Line1"; tdcShipment.CustomerAddress.PostCode = "NN8 1NB"; tdcShipment.ShipmentNumber = "ShipNo"; tdcShipment.ShipmentName = "ShipmentName"; tdcShipment.ShipmentAddress.Line1 = "Line1"; tdcShipment.ShipmentAddress.PostCode = "NN8 1NB"; tdcShipment.SalesBranchCode = "BranchCode"; tdcShipment.AfterTime = "11:11"; tdcShipment.BeforeTime = "10:10"; tdcShipment.TailLiftRequired = false; tdcShipment.CheckInTime = 1; tdcShipment.DivisionCode = "Div"; tdcShipment.GeneratedDateTime = DateTime.Now; tdcShipment.Status = Shipment.StatusEnum.Mapped; tdcShipment.IsRecurring = false; tdcShipment.IsValidAddress = false; tdcShipment.PAFAddress.Line1 = "Line1"; tdcShipment.PAFAddress.PostCode = "PostCode"; tdcShipment.UpdatedBy = "UpdatedBy"; tdcShipment.Instructions = "Instructions"; tdcShipment.VehicleMaxWeight = (decimal)1.1; OpCoDivision division = OpcoDivisionTests.PopulateNewItem(); OpcoDivisionTests.SaveItem(division); tdcShipment.DivisionCode = division.Code; Warehouse deliveryWarehouse = WarehouseTests.PopulateNewItem(); WarehouseTests.SaveItem(deliveryWarehouse); tdcShipment.DeliveryWarehouseCode = deliveryWarehouse.Code; Warehouse stockWarehouse = WarehouseTests.PopulateNewItem(); WarehouseTests.SaveItem(stockWarehouse); tdcShipment.StockWarehouseCode = stockWarehouse.Code; Route route = RouteTests.PopulateNewItem(); RouteTests.SaveItem(route); tdcShipment.RouteCode = route.Code; TransactionType transactionType = TransactionTypeTests.PopulateNewItem(); TransactionTypeTests.SaveItem(transactionType); tdcShipment.TransactionTypeCode = transactionType.Code; TransactionSubType transactionSubType = TransactionSubTypeTests.PopulateNewItem(); TransactionSubTypeTests.SaveItem(transactionSubType); tdcShipment.TransactionSubTypeCode = transactionSubType.Code; return(tdcShipment); }
internal int SaveItem(OpCoShipment opCoShipment) { return(OpCoShipmentController.SaveShipment(opCoShipment)); }
/// <summary> /// Processes the request. /// </summary> /// <param name="requestMessage">The request message.</param> public override void ProcessRequest(RequestMessage requestMessage) { try { // Get the opco shipment from the request processor if (!RequestProcessor.RequestDictionary.ContainsKey("OpCoShipment") || RequestProcessor.RequestDictionary["OpCoShipment"] == null) { // Failed to retrieve the opco shipment from the processor throw new Exception("Attempting to map an Op Co Shipment but it was not found in the Request Processor. Make sure that the shipment parser has been subscribed before the shipment mapper."); } // Get the cached opco shipment from the processor opCoShipment = (OpCoShipment)RequestProcessor.RequestDictionary["OpCoShipment"]; // Get the audit entry from the processor if we have one (optional) if (RequestProcessor.RequestDictionary.ContainsKey("AuditEntry") && RequestProcessor.RequestDictionary["AuditEntry"] != null) { // Get the cached audit entry from the processor auditEntry = (MessageAuditEntry)RequestProcessor.RequestDictionary["AuditEntry"]; } // ***************************************************************** // ** SEE IF WE HAVE AN EXISTING OPCO SHIPMENT // ***************************************************************** // See if we already have the shipment in the db existingOpCoShipment = OpCoShipmentController.GetShipment( opCoShipment.OpCoCode, opCoShipment.ShipmentNumber, opCoShipment.DespatchNumber); // Did we find an existing opco shipment if (null != existingOpCoShipment) { // We've found the shipment, make sure that our sequence number is later if (existingOpCoShipment.OpCoSequenceNumber >= opCoShipment.OpCoSequenceNumber) { // Consume the message as it's old Status = SubscriberStatusEnum.Processed; // Log that the shipment cannot be updated Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry( string.Format("Unable to update existing opco shipment {0} - {1} for for opco {2}. The request sequence number is {3} but sequence {4} has already been processed.", opCoShipment.ShipmentNumber, opCoShipment.DespatchNumber, opCoShipment.OpCoCode, opCoShipment.OpCoSequenceNumber, existingOpCoShipment.OpCoSequenceNumber), "Request Management", 0, 0, TraceEventType.Information, "Request Management", null); // Write to the log Logger.Write(logEntry); // done return; } else { // See if we need to update the tdc shipment if (existingOpCoShipment.Status == Shipment.StatusEnum.Mapped) { // ***************************************************************** // ** SEE IF WE HAVE AN EXISTING TDC SHIPMENT // ***************************************************************** // Get the existing tdc shipment existingTDCShipment = TDCShipmentController.GetShipment( opCoShipment.OpCoCode, opCoShipment.ShipmentNumber, opCoShipment.DespatchNumber); // Did we find an existing tdc shipment? if (null != existingTDCShipment) { // See if the tdc shipment can be updated if (existingTDCShipment.Status != Shipment.StatusEnum.Mapped) { // Consume the message, we can't make the update Status = SubscriberStatusEnum.Consumed; // Log that the shipment cannot be updated Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry( string.Format("Unable to update existing tdc shipment {0} - {1} for for opco {2}. The status of the existing tdc shipment is {3} disallowing this update.", existingTDCShipment.ShipmentNumber, existingTDCShipment.DespatchNumber, existingTDCShipment.OpCoCode, existingTDCShipment.Status), "Request Management", 0, 0, TraceEventType.Information, "Request Management", null); // Write to the log Logger.Write(logEntry); // done return; } } else { // We should have found the tdc shipment Status = SubscriberStatusEnum.Failed; // Log that the tdc shipment cannot be updated Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry( string.Concat("Unable to update tdc shipment ", opCoShipment.ShipmentNumber, "-", opCoShipment.DespatchNumber, " for opco ", opCoShipment.OpCoCode, ". The tdc shipment was not found."), "Request Management", 0, 0, TraceEventType.Error, "Request Management", null); // Write to the log Logger.Write(logEntry); // done return; } } } } // ***************************************************************** // ** SAVE OR UPDATE THE OPCO SHIPMENT // ***************************************************************** // See if we have an existing opco shipment if (null != existingOpCoShipment) { // Update existing opco shipment opCoShipment = (OpCoShipment)existingOpCoShipment.UpdateFromShipment(opCoShipment); } // Specify that the shipment was updated by this subscriber opCoShipment.UpdatedBy = this.GetType().FullName; // See if the shipment has been cancelled if (0 == opCoShipment.TotalLineQuantity) { // Cancel the shipment opCoShipment.Status = Shipment.StatusEnum.Cancelled; } else if (opCoShipment.OpCoHeld) { // Hold the shipment opCoShipment.Status = Shipment.StatusEnum.Held; } // See if we have an audit entry (not required) if (null != auditEntry) { // Store the audit entry id opCoShipment.AuditId = auditEntry.Id; } // Save the opco shipment to the db if (-1 != OpCoShipmentController.SaveShipment(opCoShipment)) { // Cache the opco shipment for other subscribers RequestProcessor.RequestDictionary["OpCoShipment"] = opCoShipment; // ***************************************************************** // ** MAP AND SAVE THE TDC SHIPMENT // ***************************************************************** // We only create the TDC Shipment if the OpCo Shipment has not been cancelled // If it has been cancelled and we have an existing TDC Shipment we still update it if (opCoShipment.Status != Shipment.StatusEnum.Cancelled || null != existingTDCShipment) { try { // Map the opco shipment to a new tdc shipment tdcShipment = opCoShipment.MapToTDC(existingTDCShipment, this.GetType().FullName, true); // Store the tdc shipment for other subscribers RequestProcessor.RequestDictionary["TDCShipment"] = tdcShipment; } catch (Exception ex) { // Log that the shipment cannot be updated Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry logEntry = new Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry( string.Format("The opco shipment {0} - {1} for opco {2} has a status of NOTMAPPED. The error was {3}", opCoShipment.ShipmentNumber, opCoShipment.DespatchNumber, opCoShipment.OpCoCode, ex.Message), "Request Management", 0, 0, TraceEventType.Error, "Request Management", null); // Write to the log Logger.Write(logEntry); } } // Processed Status = SubscriberStatusEnum.Processed; } else { // We failed to save the op co shipment } } catch (Exception ex) { // Store the exception LastError = ex; // Failed Status = SubscriberStatusEnum.Failed; } finally { // Cleanup existingOpCoShipment = null; existingTDCShipment = null; } }