internal bool DeleteItem(int Id) { OpCo opco = new OpCo(); opco.Id = Id; return(OpCoShipmentController.DeleteShipment(Id)); }
protected void dataSourceShipments_Selecting(object sender, ObjectDataSourceSelectingEventArgs e) { // Assign our shipment criteria, query has not ran yet e.InputParameters["criteria"] = ShipmentCriteriaUserControl.Criteria; // Page number and max rows e.Arguments.MaximumRows = OpCoShipmentsUserControl.PageSize; e.Arguments.StartRowIndex = OpCoShipmentsUserControl.PageIndex; // Get the total number of rows OpCoShipmentsUserControl.TotalRows = OpCoShipmentController.GetShipmentsCount(ShipmentCriteriaUserControl.Criteria); // Sorting e.Arguments.SortExpression = string.Concat(OpCoShipmentsUserControl.SortExpression, " ", OpCoShipmentsUserControl.SortDirection.ToString()); }
protected void btnMapToTdc_Click(object sender, System.EventArgs e) { // Get the opco shipment Discovery.BusinessObjects.OpCoShipment opCoShipment = OpCoShipmentController.GetShipment(Convert.ToInt32((sender as System.Web.UI.WebControls.IButtonControl).CommandArgument)); // Make sure that we found the shipment if (null != opCoShipment && opCoShipment.Id != -1) { // We have the shipment, now map it to a tdc shipment if not mapped if (opCoShipment.Status == Shipment.StatusEnum.NotMapped) { // The new shipment Discovery.BusinessObjects.TDCShipment tdcShipment; try { // Map opco shipment tdcShipment = opCoShipment.MapToTDC(null, Page.User.Identity.Name, false); // Update the status of the opco shipment to mapped opCoShipment.Status = Shipment.StatusEnum.Mapped; // Update the opco shipment status OpCoShipmentController.UpdateShipmentStatus(opCoShipment); // Display message DiscoveryPage.DisplayMessage(string.Format("The OpCo shipment was mapped to a new TDC shipment <a href=\"TDCShipment.aspx?Id={0}\">{1}-{2}</a>.", tdcShipment.Id, tdcShipment.ShipmentNumber, tdcShipment.DespatchNumber), DiscoveryMessageType.Success, Page.Master); } catch (Exception ex) { DiscoveryPage.DisplayMessage(ex.Message, DiscoveryMessageType.Error, Page.Master); } // Status changed, re bind the data OpCoShipmentFormView.DataBind(); } } }
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); } }
protected void discoveryShipments_ItemCommand(object source, RepeaterCommandEventArgs e) { switch (e.CommandName) { case "Sort": { // Bind data discoveryShipments.DataBind(); // Done break; } case "OpCoDetail": { if (null != Redirecting) { OpCoRedirectEventArg redirectEventArgs = new OpCoRedirectEventArg(); Redirecting(ref redirectEventArgs); if (!redirectEventArgs.CancelRedirect) { // Redirect to the details page Response.Redirect(string.Format("~/Shipments/OpCoShipment.aspx?Id={0}&{1}", e.CommandArgument.ToString(), Discovery.Utility.UIHelper.GenerateUrlReferrer(HttpContext.Current, new string[] { redirectEventArgs.QueryParams, string.Concat("PageIndex=", discoveryPager.PageIndex.ToString()), string.Concat("PageSize=", discoveryPager.PageSize.ToString()), string.Concat("SortExpression=", string.Concat(discoveryShipments.SortExpression, " ", discoveryShipments.SortDirection.ToString())) }))); } } // Done; break; } case "TDCDetail": { if (null != Redirecting) { OpCoRedirectEventArg redirectEventArgs = new OpCoRedirectEventArg(); Redirecting(ref redirectEventArgs); if (!redirectEventArgs.CancelRedirect) { // Get the opco code, shipment number and the despatch number for the tdc shipment string[] shipmentParams = e.CommandArgument.ToString().Split('|'); // Get the tdc shipment Discovery.BusinessObjects.TDCShipment tdcShipment = TDCShipmentController.GetShipment(shipmentParams[0], shipmentParams[1], shipmentParams[2]); if (null != tdcShipment) { // Redirect to the details page Response.Redirect(string.Format("~/Shipments/TDCShipment.aspx?Id={0}&{1}", tdcShipment.Id, Discovery.Utility.UIHelper.GenerateUrlReferrer(HttpContext.Current, new string[] { redirectEventArgs.QueryParams, string.Concat("PageIndex=", discoveryPager.PageIndex.ToString()), string.Concat("PageSize=", discoveryPager.PageSize.ToString()), string.Concat("SortExpression=", string.Concat(discoveryShipments.SortExpression, " ", discoveryShipments.SortDirection.ToString())) }))); } } } // Done; break; } case "AuditDetail": { if (null != Redirecting) { OpCoRedirectEventArg redirectEventArgs = new OpCoRedirectEventArg(); Redirecting(ref redirectEventArgs); if (!redirectEventArgs.CancelRedirect) { // Redirect to the details page Response.Redirect(string.Format("~/Admin/MessageAudit.aspx?Id={0}&{1}", e.CommandArgument.ToString(), Discovery.Utility.UIHelper.GenerateUrlReferrer(HttpContext.Current, new string[] { redirectEventArgs.QueryParams, string.Concat("PageIndex=", discoveryPager.PageIndex.ToString()), string.Concat("PageSize=", discoveryPager.PageSize.ToString()), string.Concat("SortExpression=", string.Concat(discoveryShipments.SortExpression, " ", discoveryShipments.SortDirection.ToString())) }))); } } // Done break; } case "MapToTdc": { // Get the opco shipment Discovery.BusinessObjects.OpCoShipment opCoShipment = OpCoShipmentController.GetShipment(Convert.ToInt32(e.CommandArgument)); // Make sure that we found the shipment if (null != opCoShipment && opCoShipment.Id != -1) { // We have the shipment, now map it to a tdc shipment if not mapped if (opCoShipment.Status == Shipment.StatusEnum.NotMapped) { // The new shipment TDCShipment tdcShipment; try { //see if there is an existing TDCShipment TDCShipment existingTDCShipment = TDCShipmentController.GetShipment( opCoShipment.OpCoCode, opCoShipment.ShipmentNumber, opCoShipment.DespatchNumber); // Map opco shipment tdcShipment = opCoShipment.MapToTDC(existingTDCShipment, Page.User.Identity.Name, false); // Update the opco shipment status OpCoShipmentController.UpdateShipmentStatus(opCoShipment); // Display message DiscoveryPage.DisplayMessage(string.Format("The OpCo shipment was mapped to a new TDC shipment <a href=\"TDCShipment.aspx?Id={0}\">{1}-{2}</a>.", tdcShipment.Id, tdcShipment.ShipmentNumber, tdcShipment.DespatchNumber), DiscoveryMessageType.Success, Page.Master); } catch (Exception ex) { DiscoveryPage.DisplayMessage(ex.Message, DiscoveryMessageType.Error, Page.Master); } // Status changed, re bind the data discoveryShipments.DataBind(); } } // Done; break; } } }
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 OpCoShipment GetItem(int id, bool recursive) { return(OpCoShipmentController.GetShipment(id)); }
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; } }
/// <summary> /// Maps to TDC. /// </summary> /// <returns></returns> public TDCShipment MapToTDC(TDCShipment existingTDCShipment, string updatedBy, bool raiseAddressException) { try { // Create an instance of a tdc shipment TDCShipment tdcShipment = new TDCShipment(); // Map the opco shipment to a tdc shipment Mapper.Map(this, tdcShipment, this.OpCoCode, "TDC", null, new string[] { "Id" }); // Update the opco shipment id in the tdc shipment tdcShipment.OpCoShipmentId = this.Id; // Map the opcoshipmentlines to tdcshipment lines via the mapper class List <ShipmentLine> tdcShipmentLines = new List <ShipmentLine>(this.ShipmentLines.Count); // Map the lines from opcoshipmentlines to tdcshipmentlines foreach (ShipmentLine opCoShipmentLine in this.ShipmentLines) { // The new tdc shipment line TDCShipmentLine tdcShipmentLine = new TDCShipmentLine(); // Map the opco shipment to a tdc shipment Mapper.Map(opCoShipmentLine, tdcShipmentLine, this.OpCoCode, "TDC", null, new string[] { "Id" }); //store the original quantity for later validation which stops the user from //increasing the quantity past this original quantity. tdcShipmentLine.OriginalQuantity = tdcShipmentLine.Quantity; // Add the tdcshipmentline to the tdcshipmentlines list tdcShipmentLines.Add(tdcShipmentLine); } // Store the new tdc shipment lines in the tdcshipment tdcShipment.ShipmentLines = tdcShipmentLines; // ******************************** // ** UPDATE EXISTING TDC SHIPMENT // ******************************** if (null != existingTDCShipment) { // Update the existing tdc shipment with the one just mapped tdcShipment = (TDCShipment)existingTDCShipment.UpdateFromShipment(tdcShipment); } // Update the status of the tdc shipment to mapped tdcShipment.Status = StatusEnum.Mapped; // See if the tdc shipment has been cancelled if (0 == tdcShipment.TotalLineQuantity) { // Cancel the shipment tdcShipment.Status = Shipment.StatusEnum.Cancelled; } // If the tdc shipment is valid and not cancelled, execute remaining business logic if (tdcShipment.IsValid) { // ********************************************************************************* // ** Tec Spec 5.3, Calculate the estimated delivery date of the tdc shipment // ********************************************************************************* tdcShipment.CalculateDeliveryDate(); // ********************************************************************************* // ** Tec Spec 5.4, Check the address // ********************************************************************************* tdcShipment.CheckAddress(); // Specify that the shipment was update tdcShipment.UpdatedBy = updatedBy; // Save the tdc shipment TDCShipmentController.SaveShipment(tdcShipment); //if an invalid address should be logged or emailed then call the NotifyIfPoorAddressMatch method. //This method will check if there was a poor match an pass an exception to the exception handling if (raiseAddressException) { tdcShipment.NotifyIfPoorAddressMatch(); } // ******************************** // ** UPDATE THIS OPCO SHIPMENT // ******************************** // Update the opco shipment status if the shipment is NOTMAPPED if (this.Status == Shipment.StatusEnum.NotMapped) { // Update the status of the opco shipment to mapped this.Status = Shipment.StatusEnum.Mapped; // Update the opco shipment status OpCoShipmentController.UpdateShipmentStatus(this); } } else { // The tdc shipment was is invalid throw new InValidBusinessObjectException(tdcShipment); } // Return the new tdc shipment return(tdcShipment); } catch (Exception ex) { // Generate a new exception ex = new FailedShipmentMappingException( this.OpCoCode, this.OpCoContact.Email, string.Format("Failed to map OpCo shipment {0} - {1} for OpCo {2}. {3}", this.ShipmentNumber, this.DespatchNumber, this.OpCoCode, ex.Message)); // Log an throw if configured to do so if (ExceptionPolicy.HandleException(ex, "Business Logic")) { throw ex; } // We failed to save the shipment return(null); } }