private void btnNext_Click(object sender, EventArgs e) { if (Page.IsValid) { #region Create the new point Entities.Point newPoint = new Entities.Point(); Facade.IPostTown facPostTown = new Facade.Point(); Entities.PostTown town = facPostTown.GetPostTownForTownId((int)Session[wizard.C_TOWN_ID]); // Set the point owner and description newPoint.IdentityId = (int)Session[wizard.C_POINT_FOR]; newPoint.Description = Session[wizard.C_POINT_NAME].ToString(); // Get the point type switch ((ePointType)Session[wizard.C_POINT_TYPE]) { case ePointType.Collect: newPoint.Collect = true; break; case ePointType.Deliver: newPoint.Deliver = true; break; case ePointType.Any: newPoint.Collect = true; newPoint.Deliver = true; break; } // set the address Entities.Address address = new Entities.Address(); address.AddressLine1 = txtAddressLine1.Text; address.AddressLine2 = txtAddressLine2.Text; address.AddressLine3 = txtAddressLine3.Text; address.AddressType = eAddressType.Point; address.County = txtCounty.Text; address.IdentityId = newPoint.IdentityId; address.Latitude = Decimal.Parse(txtLatitude.Text); address.Longitude = Decimal.Parse(txtLongitude.Text); address.PostCode = txtPostCode.Text; address.PostTown = txtPostTown.Text; if (address.TrafficArea == null) { address.TrafficArea = new Orchestrator.Entities.TrafficArea(); } address.TrafficArea.TrafficAreaId = Convert.ToInt32(hidTrafficArea.Value); newPoint.Address = address; newPoint.Longitude = address.Longitude; newPoint.Latitude = address.Latitude; Facade.IOrganisation facOrganisation = new Facade.Organisation(); Orchestrator.Entities.Organisation organisation = facOrganisation.GetForIdentityId(newPoint.IdentityId); // set the radius if the address was changed by addressLookup // if the org has a default, use it, if not, use the system default. if (!String.IsNullOrEmpty(this.hdnSetPointRadius.Value)) { if (organisation.Defaults[0].DefaultGeofenceRadius == null) { newPoint.Radius = Globals.Configuration.GPSDefaultGeofenceRadius; } else { newPoint.Radius = organisation.Defaults[0].DefaultGeofenceRadius; } } newPoint.PostTown = town; newPoint.PointNotes = txtPointNotes.Text; string userId = ((Entities.CustomPrincipal)Page.User).UserName; // Create the new point Facade.IPoint facPoint = new Facade.Point(); Entities.FacadeResult result = facPoint.Create(newPoint, userId); int pointId = facPoint.Create(newPoint, userId).ObjectId; #endregion if (pointId == 0) { // This customer already has a point with this name // Try to locate the point Entities.PointCollection points = facPoint.GetClientPointsForName(newPoint.IdentityId, newPoint.Description); if (points.Count == 1) { // The point id has been found! pointId = points[0].PointId; } else { // Clear the session variables used to help add the new point Session[wizard.C_POINT_TYPE] = null; Session[wizard.C_POINT_FOR] = null; Session[wizard.C_POINT_NAME] = null; Session[wizard.C_TOWN_ID] = null; GoToStep("P"); } } if (pointId > 0) { // Reload the point to ensure we have all the ancillary entities Entities.Point createdPoint = facPoint.GetPointForPointId(pointId); if (m_isUpdate) { // Add the collect drop point information if (m_instruction == null) { m_instruction = new Entities.Instruction(); m_instruction.JobId = m_jobId; switch ((ePointType)(int)Session[wizard.C_POINT_TYPE]) { case ePointType.Collect: m_instruction.InstructionTypeId = (int)eInstructionType.Load; break; case ePointType.Deliver: m_instruction.InstructionTypeId = (int)eInstructionType.Drop; break; } } m_instruction.Point = createdPoint; m_instruction.PointID = createdPoint.PointId; m_instruction.InstructionID = m_instruction.InstructionID; if (m_instruction.InstructionTypeId == (int)eInstructionType.Drop) { m_instruction.ClientsCustomerIdentityID = createdPoint.IdentityId; } // Cause the first docket to be displayed. if (m_instruction.CollectDrops.Count > 0) { Session[wizard.C_COLLECT_DROP] = m_instruction.CollectDrops[0]; Session[wizard.C_COLLECT_DROP_INDEX] = 0; } Session[wizard.C_INSTRUCTION] = m_instruction; } else { if (m_isAmendment) { if (pointId != m_instruction.PointID) { m_instruction.Point = createdPoint; m_instruction.PointID = createdPoint.PointId; } // Cause the first docket to be displayed. if (m_instruction.CollectDrops.Count > 0) { Session[wizard.C_COLLECT_DROP] = m_instruction.CollectDrops[0]; Session[wizard.C_COLLECT_DROP_INDEX] = 0; } Session[wizard.C_INSTRUCTION] = m_instruction; } else { // Add the collect drop point information if (m_instruction == null) { m_instruction = new Entities.Instruction(); m_instruction.JobId = m_jobId; switch ((ePointType)(int)Session[wizard.C_POINT_TYPE]) { case ePointType.Collect: m_instruction.InstructionTypeId = (int)eInstructionType.Load; break; case ePointType.Deliver: m_instruction.InstructionTypeId = (int)eInstructionType.Drop; break; } } m_instruction.Point = createdPoint; m_instruction.PointID = createdPoint.PointId; m_instruction.InstructionID = m_instruction.InstructionID; if (m_instruction.InstructionTypeId == (int)eInstructionType.Drop) { m_instruction.ClientsCustomerIdentityID = createdPoint.IdentityId; } Session[wizard.C_INSTRUCTION] = m_instruction; } } GoToStep("PD"); } } }