public Orchestrator.WebUI.Services.Point UpdatePoint(Orchestrator.WebUI.Services.Point p, string userId) { Orchestrator.WebUI.Services.Point returnPoint = null; Orchestrator.Facade.IPoint facPoint = new Orchestrator.Facade.Point(); Orchestrator.Entities.Point selectedPoint = facPoint.GetPointForPointId(p.PointID); selectedPoint.Description = p.Description; selectedPoint.Latitude = (decimal)p.Latitide; selectedPoint.Longitude = (decimal)p.Longitude; selectedPoint.PostTown.TownId = p.ClosestTownID; selectedPoint.PostTown.TownName = p.ClosestTown; selectedPoint.PointNotes = p.PointNotes; selectedPoint.PointCode = p.PointCode; selectedPoint.PhoneNumber = p.PhoneNumber; selectedPoint.Address.AddressLine1 = p.AddressLine1; selectedPoint.Address.AddressLine2 = p.AddressLine2; selectedPoint.Address.AddressLine3 = p.AddressLine3; selectedPoint.Address.PostTown = p.PostTown; selectedPoint.Address.County = p.County; selectedPoint.Address.PostCode = p.PostCode; selectedPoint.Address.CountryId = p.CountryID; selectedPoint.Address.CountryDescription = p.CountryDescription; Entities.FacadeResult facResult = facPoint.Update(selectedPoint, userId); if (facResult.Success) { returnPoint = this.GetPointForWebService(selectedPoint.PointId); } else { foreach (BusinessRuleInfringement i in facResult.Infringements) { p.ErrorMeesage += String.Format("{0} : {1}{2}", i.Key, i.Description, Environment.NewLine); } returnPoint = p; } return(returnPoint); }
protected void btnApprovePoint_Click(object sender, EventArgs e) { int orderId = Convert.ToInt32(Request.QueryString["OrderId"].ToString()); int pointId = Convert.ToInt32(Request.QueryString["PointId"].ToString()); Facade.Point facPoint = new Orchestrator.Facade.Point(); Entities.Point point = facPoint.GetPointForPointId(pointId); Facade.IOrganisation facOrg = new Facade.Organisation(); Entities.Organisation org = facOrg.GetForName(point.OrganisationName); Entities.FacadeResult res = null; using (TransactionScope ts = new TransactionScope()) { if (org.IdentityStatus == eIdentityStatus.Unapproved) { // Set the identityStatus to approved org.IdentityStatus = eIdentityStatus.Active; facOrg.Update(org, this.Page.User.Identity.Name); } point.PointStateId = ePointState.Approved; res = facPoint.Update(point, this.Page.User.Identity.Name); ts.Complete(); } if (res.Success) { this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "ApprovePoint", "window.opener.__doPostBack('','Refresh');window.close();", true); } else { idErrors.Infringements = res.Infringements; idErrors.DisplayInfringments(); idErrors.Visible = true; } }
void btnAlterPoint_Click(object sender, EventArgs e) { Page.Validate("AlterPoint"); if (Page.IsValid) { int ownerID = 0; #region Validate that the Point Name is Unique for this Organisation bool foundPointName = false; lblError.Visible = false; Orchestrator.Facade.IPoint facPoint = new Orchestrator.Facade.Point(); Entities.Point point = facPoint.GetPointForPointId(PointID); ownerID = new Facade.Organisation().GetForName(cboNewPointOwner.Text).IdentityId; DataSet pointNames = facPoint.GetAllForOrganisation(ownerID, ePointType.Any, txtDescription.Text); foreach (DataRow row in pointNames.Tables[0].Rows) { if (((string)row["Description"]) == txtDescription.Text && point.PointId != (int)row["PointId"]) { foundPointName = true; } } #endregion if (foundPointName) { 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 { Orchestrator.Facade.IPostTown facPostTown = new Orchestrator.Facade.Point(); Orchestrator.Entities.PostTown town = facPostTown.GetPostTownForTownId(int.Parse(cboClosestTown.SelectedValue)); // Set the point owner and description point.OrganisationName = cboPoint.Text; point.IdentityId = ownerID; point.Description = txtDescription.Text; point.PointCode = this.txtPointCode.Text; // Get the point type switch (this.PointType) { case ePointType.Collect: point.Collect = true; break; case ePointType.Deliver: point.Deliver = true; break; case ePointType.Any: point.Collect = true; point.Deliver = true; break; } // set the address Orchestrator.Entities.Address address = new Orchestrator.Entities.Address(); address.AddressLine1 = txtAddressLine1.Text; address.AddressLine2 = txtAddressLine2.Text; address.AddressLine3 = txtAddressLine3.Text; address.AddressType = eAddressType.Point; address.County = txtCounty.Text; address.CountryDescription = this.cboCountry.Text; address.CountryId = Convert.ToInt32(this.cboCountry.SelectedValue); address.IdentityId = ownerID; decimal latitude = 0; if (decimal.TryParse(hidLat.Value, out latitude)) { address.Latitude = latitude; } decimal longitude = 0; if (decimal.TryParse(hidLon.Value, out longitude)) { address.Longitude = longitude; } address.PostCode = txtPostCode.Text.ToUpper(); address.PostTown = txtPostTown.Text; if (address.TrafficArea == null) { address.TrafficArea = new Orchestrator.Entities.TrafficArea(); } Facade.IOrganisation facOrganisation = new Facade.Organisation(); Orchestrator.Entities.Organisation organisation = facOrganisation.GetForIdentityId(point.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 != null) { if (organisation.Defaults.Count > 0 && organisation.Defaults[0].DefaultGeofenceRadius.HasValue) { point.Radius = organisation.Defaults[0].DefaultGeofenceRadius; } else { point.Radius = Globals.Configuration.GPSDefaultGeofenceRadius; } } else { point.Radius = Globals.Configuration.GPSDefaultGeofenceRadius; } } // Get the Traffic Area for this Point address.TrafficArea.TrafficAreaId = Convert.ToInt32(cboTrafficArea.SelectedValue); point.Address = address; point.Longitude = address.Longitude; point.Latitude = address.Latitude; point.PostTown = town; point.PointNotes = txtPointNotes.Text; if (ClientUserOrganisationIdentityID > 0) { point.PointStateId = ePointState.Unapproved; } else { point.PointStateId = ePointState.Approved; } point.PhoneNumber = txtPhoneNumber.Text; string userId = ((Orchestrator.Entities.CustomPrincipal)Page.User).UserName; // Create the new point Entities.FacadeResult result = facPoint.Update(point, userId); if (result.Success) { // get the Point with all parts populated. this.SelectedPoint = point; cboPoint.Text = point.Description; cboPoint.SelectedValue = point.IdentityId.ToString() + "," + point.PointId.ToString(); pnlNewPoint.Visible = false; pnlPoint.Visible = true; inpCreateNewPointSelected.Value = string.Empty; } else { for (int i = 0; i < result.Infringements.Count; i++) { lblError.Text += result.Infringements[i].Description + Environment.NewLine; } lblError.ForeColor = Color.Red; lblError.Visible = true; pnlPoint.Visible = false; pnlNewPoint.Visible = true; pnlFullAddress.Visible = false; } } } }