protected void Page_Load(object sender, EventArgs e) { Int64 forNoteTypeId = 0; if (MercuryApplication == null) { return; } if ((!MercuryApplication.HasEnvironmentPermission(Mercury.Server.EnvironmentPermissions.NoteTypeReview)) && (!MercuryApplication.HasEnvironmentPermission(Mercury.Server.EnvironmentPermissions.NoteTypeManage))) { Response.Redirect("/PermissionDenied.aspx", true); return; } if (!Page.IsPostBack) { #region Initial Page Load if (Request.QueryString["NoteTypeId"] != null) { forNoteTypeId = Int64.Parse(Request.QueryString["NoteTypeId"]); } if (forNoteTypeId != 0) { noteType = MercuryApplication.NoteTypeGet(forNoteTypeId, false); if (noteType == null) { noteType = new Mercury.Client.Core.Reference.NoteType(MercuryApplication); } } else { noteType = new Mercury.Client.Core.Reference.NoteType(MercuryApplication); } InitializeAll(); Session[SessionCachePrefix + "NoteType"] = noteType; Session[SessionCachePrefix + "NoteTypeUnmodified"] = noteType.Copy(); #endregion } // Initial Page Load else // Postback { noteType = (Mercury.Client.Core.Reference.NoteType)Session[SessionCachePrefix + "NoteType"]; } ApplySecurity(); if (!String.IsNullOrEmpty(noteType.Name)) { Page.Title = "Note Type - " + noteType.Name; } else { Page.Title = "Note Type"; } return; }
protected Boolean ApplyChanges() { Boolean isModified = false; Boolean success = false; Boolean isValid = false; System.Collections.Generic.Dictionary <String, String> validationResponse; Mercury.Client.Core.Reference.NoteType noteTypeUnmodified = (Mercury.Client.Core.Reference.NoteType)Session[SessionCachePrefix + "NoteTypeUnmodified"]; if (noteTypeUnmodified.Id == 0) { isModified = true; } noteType.Name = NoteTypeName.Text.Trim(); noteType.Description = NoteTypeDescription.Text.Trim(); noteType.Enabled = NoteTypeEnabled.Checked; noteType.Visible = NoteTypeVisible.Checked; if (!isModified) { isModified = !noteType.IsEqual(noteTypeUnmodified); } validationResponse = noteType.Validate(); isValid = (validationResponse.Count == 0); if ((isModified) && (isValid)) { success = MercuryApplication.NoteTypeSave(noteType); if (success) { noteType = MercuryApplication.NoteTypeGet(noteType.Id, false); Session[SessionCachePrefix + "NoteType"] = noteType; Session[SessionCachePrefix + "NoteTypeUnmodified"] = noteType.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); }