private bool AddPoint() { if (_point != null) { Facade.IPoint facPoint = new Facade.Point(); string userName = ((Entities.CustomPrincipal)Page.User).UserName; Entities.FacadeResult retVal = facPoint.Create(_point, userName); return(retVal.Success); } return(false); }
/// <summary> /// Creates a new point based on the separate parts of the point passed as arguements. /// </summary> /// <param name="organisationId">The identity id of the organisation this point is registered to.</param> /// <param name="organisationName">The name of the organisation this point is registered to.</param> /// <param name="closestTownId">The id of the town id that is closest to this point.</param> /// <param name="description">The description that should be given to this point.</param> /// <param name="addressLine1">The first line of the address.</param> /// <param name="addressLine2">The second line of the address.</param> /// <param name="addressLine3">The third line of the address.</param> /// <param name="postTown">The town.</param> /// <param name="county">The county the point is within.</param> /// <param name="postCode">The post code.</param> /// <param name="longitude">The longitude attached to this point.</param> /// <param name="latitude">The latitude attached to this point.</param> /// <param name="trafficAreaId">The traffic area for this point.</param> /// <param name="userId">The id of the user creating this point.</param> /// <returns>The id of the new point created, or 0 if there were infringments encountered.</returns> private int CreateNewPoint(int organisationId, string organisationName, int closestTownId, string description, string addressLine1, string addressLine2, string addressLine3, string postTown, string county, string postCode, decimal longitude, decimal latitude, int trafficAreaId, string userId) { Entities.FacadeResult retVal = null; Entities.Point point = new Entities.Point(); point.Address = new Entities.Address(); point.Address.AddressLine1 = addressLine1; point.Address.AddressLine2 = addressLine2; point.Address.AddressLine3 = addressLine3; point.Address.PostTown = postTown; point.Address.County = county; point.Address.PostCode = postCode; point.Address.Longitude = longitude; point.Address.Latitude = latitude; point.Address.TrafficArea = new Entities.TrafficArea(); point.Address.TrafficArea.TrafficAreaId = trafficAreaId; point.Address.AddressType = eAddressType.Point; point.Description = description; point.IdentityId = organisationId; point.Latitude = latitude; point.Longitude = longitude; point.OrganisationName = organisationName; Facade.IPostTown facPostTown = new Facade.Point(); point.PostTown = facPostTown.GetPostTownForTownId(closestTownId); Facade.IPoint facPoint = new Facade.Point(); retVal = facPoint.Create(point, userId); if (retVal.Success) { return(retVal.ObjectId); } else { infringementDisplay.Infringements = retVal.Infringements; infringementDisplay.DisplayInfringments(); return(0); } }
private bool AddPoint() { Facade.IPoint facPoint = new Facade.Point(); string userName = ((Entities.CustomPrincipal)Page.User).UserName; Entities.FacadeResult retVal = facPoint.Create(point, userName); if (retVal.Success) { lblConfirmation.Text = "The point was added."; lblConfirmation.Visible = true; ViewState["pointId"] = retVal.ObjectId; point = facPoint.GetPointForPointId(retVal.ObjectId); ViewState["point"] = point; cboClient.Enabled = false; PopulateTrafficAreaControl(); cboTrafficArea.Visible = true; lblTrafficArea.Visible = true; cboTrafficArea.Items.FindByValue(point.Address.TrafficArea.TrafficAreaId.ToString()).Selected = true; btnAdd.Text = "Update"; m_isUpdate = true; PopulateTrafficAreaControl(); } else { infringementDisplay.Infringements = retVal.Infringements; infringementDisplay.DisplayInfringments(); } return(retVal.Success); }
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"); } } }
protected void CreatePoint() { if (Page.IsValid) { string userID = ((Orchestrator.Entities.CustomPrincipal)Page.User).UserName; var ownerIdentityID = string.IsNullOrWhiteSpace(cboNewPointOwner.SelectedValue) ? (int?)null : int.Parse(cboNewPointOwner.SelectedValue); var closestTownID = int.Parse(cboClosestTown.SelectedValue); var countryID = int.Parse(cboCountry.SelectedValue); var trafficAreaID = int.Parse(cboTrafficArea.SelectedValue); decimal latitude = 0; decimal longitude = 0; decimal.TryParse(hidLat.Value, out latitude); decimal.TryParse(hidLon.Value, out longitude); Facade.IPoint facPoint = new Facade.Point(); var result = facPoint.Create( ownerIdentityID, cboNewPointOwner.Text, txtDescription.Text, closestTownID, txtAddressLine1.Text, txtAddressLine2.Text, txtAddressLine3.Text, txtPostTown.Text, txtCounty.Text, txtPostCode.Text.ToUpper(), countryID, latitude, longitude, this.PointType, txtPointCode.Text, txtPointNotes.Text, txtPhoneNumber.Text, trafficAreaID, this.ClientUserOrganisationIdentityID, userID); if (!result.Success) { if (result.Infringements.Any(bri => bri.Key == typeof(Orchestrator.BusinessRules.eBRPoint).FullName + "." + BusinessRules.eBRPoint.PointNameAlreadyExistsForClient.ToString())) { lblError.Text = "The Description must be unique for this organisation."; lblError.ForeColor = Color.Red; lblError.Visible = true; pnlPoint.Visible = false; pnlNewPoint.Visible = true; pnlFullAddress.Visible = false; } } else if (result.ObjectId > 0) { // get the Point with all parts populated. var newPoint = facPoint.GetPointForPointId(result.ObjectId); this.SelectedPoint = newPoint; cboPoint.Text = newPoint.Description; cboPoint.SelectedValue = newPoint.IdentityId.ToString() + "," + newPoint.PointId.ToString(); if (SelectedPointChanged != null) { SelectedPointChanged(this, new SelectedPointChangedEventArgs(this.SelectedPoint)); } this.lnkPointGeography.OnClientClick = "javascript:" + this.ClientID + "_UpdateGeography(" + this.SelectedPoint.PointId + "); return false;"; pnlNewPoint.Visible = false; pnlPoint.Visible = true; inpCreateNewPointSelected.Value = string.Empty; txtDescription.Text = newPoint.Description; } } }