protected Boolean ApplyChanges() { Boolean isModified = false; Boolean success = false; Boolean isValid = false; System.Collections.Generic.Dictionary <String, String> validationResponse; Mercury.Client.Core.Individual.CarePlan carePlanUnmodified = (Mercury.Client.Core.Individual.CarePlan)Session[SessionCachePrefix + "CarePlanUnmodified"]; if (carePlanUnmodified.Id == 0) { isModified = true; } carePlan.Name = CarePlanName.Text.Trim(); carePlan.Description = CarePlanDescription.Text.Trim(); carePlan.Enabled = CarePlanEnabled.Checked; carePlan.Visible = CarePlanVisible.Checked; if (!isModified) { isModified = !carePlan.IsEqual(carePlanUnmodified); } validationResponse = carePlan.Validate(); isValid = (validationResponse.Count == 0); if ((isModified) && (isValid)) { success = MercuryApplication.CarePlanSave(carePlan); if (success) { carePlan = MercuryApplication.CarePlanGet(carePlan.Id, false); Session[SessionCachePrefix + "CarePlan"] = carePlan; Session[SessionCachePrefix + "CarePlanUnmodified"] = carePlan.Copy(); SaveResponseLabel.Text = "Save Successful"; InitializeAll(); } else { SaveResponseLabel.Text = "Unable to Save."; if (MercuryApplication.LastException != null) { SaveResponseLabel.Text = SaveResponseLabel.Text + " [" + MercuryApplication.LastException.Message + "]"; } success = false; } } else if (!isModified) { SaveResponseLabel.Text = "No Changes Detected."; success = true; } else if (!isValid) { foreach (String validationKey in validationResponse.Keys) { SaveResponseLabel.Text = "Invalid [" + validationKey + "]: " + validationResponse[validationKey]; break; } success = false; } return(success); }
protected void Page_Load(object sender, EventArgs e) { Int64 forCarePlanId = 0; if (MercuryApplication == null) { return; } if ((!MercuryApplication.HasEnvironmentPermission(Mercury.Server.EnvironmentPermissions.CarePlanReview)) && (!MercuryApplication.HasEnvironmentPermission(Mercury.Server.EnvironmentPermissions.CarePlanManage))) { Response.Redirect("/PermissionDenied.aspx", true); return; } if (!Page.IsPostBack) { #region Initial Page Load if (Request.QueryString["CarePlanId"] != null) { forCarePlanId = Int64.Parse(Request.QueryString["CarePlanId"]); } if (forCarePlanId != 0) { carePlan = MercuryApplication.CarePlanGet(forCarePlanId, false); if (carePlan == null) { carePlan = new Mercury.Client.Core.Individual.CarePlan(MercuryApplication); } } else { carePlan = new Mercury.Client.Core.Individual.CarePlan(MercuryApplication); } InitializeAll(); Session[SessionCachePrefix + "CarePlan"] = carePlan; Session[SessionCachePrefix + "CarePlanUnmodified"] = carePlan.Copy(); #endregion } // Initial Page Load else // Postback { carePlan = (Mercury.Client.Core.Individual.CarePlan)Session[SessionCachePrefix + "CarePlan"]; } ApplySecurity(); if (!String.IsNullOrEmpty(carePlan.Name)) { Page.Title = "Care Plan - " + carePlan.Name; } else { Page.Title = "Care Plan"; } return; }