Пример #1
0
        protected Boolean ApplyChanges()
        {
            Boolean success = false;

            Boolean isModified = false;

            Boolean isValid = false;

            Dictionary <String, String> validationResponse;


            if (MercuryApplication == null)
            {
                return(false);
            }


            if (!CorrespondenceVersion.Value.HasValue)
            {
                SaveResponseLabel.Text = "A valid Version must be specified.";

                return(false);
            }



            Mercury.Client.Core.Reference.Correspondence correspondenceUnmodified = (Mercury.Client.Core.Reference.Correspondence)Session[SessionCachePrefix + "CorrespondenceUnmodified"];


            correspondence.Name = CorrespondenceName.Text;

            correspondence.Description = CorrespondenceDescription.Text;

            correspondence.Version = CorrespondenceVersion.Value.Value;

            correspondence.FormId = Convert.ToInt64(CorrespondenceFormSelection.SelectedValue);

            correspondence.StoreImage = CorrespondenceStoreImage.Checked;

            correspondence.Enabled = CorrespondenceEnabled.Checked;

            correspondence.Visible = CorrespondenceVisible.Checked;


            if (correspondenceUnmodified.Id == 0)
            {
                isModified = true;
            }

            if (!isModified)
            {
                isModified = !correspondence.IsEqual(correspondenceUnmodified);
            }


            validationResponse = correspondence.Validate();

            isValid = (validationResponse.Count == 0);


            if ((isModified) && (isValid))
            {
                if (!MercuryApplication.HasEnvironmentPermission(Mercury.Server.EnvironmentPermissions.CorrespondenceManage))
                {
                    SaveResponseLabel.Text = "Permission Denied.";

                    return(false);
                }


                success = MercuryApplication.CorrespondenceSave(correspondence);

                if (success)
                {
                    correspondence = MercuryApplication.CorrespondenceGet(correspondence.Id, false);

                    correspondence.LoadContentAttachments();

                    Session[SessionCachePrefix + "Correspondence"] = correspondence;

                    Session[SessionCachePrefix + "CorrespondenceUnmodified"] = correspondence.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);
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (MercuryApplication == null)
            {
                return;
            }


            Int64 forCorrespondenceId = 0;

            if ((!MercuryApplication.HasEnvironmentPermission(Mercury.Server.EnvironmentPermissions.CorrespondenceManage))

                && (!MercuryApplication.HasEnvironmentPermission(Mercury.Server.EnvironmentPermissions.CorrespondenceReview)))

            {
                Response.Redirect("/PermissionDenied.aspx", true); return;
            }


            if (!Page.IsPostBack)
            {
                #region Initial Page Load

                if (Request.QueryString["CorrespondenceId"] != null)
                {
                    forCorrespondenceId = Int64.Parse(Request.QueryString["CorrespondenceId"]);
                }

                if (forCorrespondenceId != 0)
                {
                    correspondence = MercuryApplication.CorrespondenceGet(forCorrespondenceId, false);

                    if (correspondence == null)
                    {
                        correspondence = new Mercury.Client.Core.Reference.Correspondence(MercuryApplication);
                    }

                    else
                    {
                        correspondence.LoadContentAttachments();
                    }
                }

                else
                {
                    correspondence = new Mercury.Client.Core.Reference.Correspondence(MercuryApplication);
                }

                InitializeAll();

                Session[SessionCachePrefix + "Correspondence"] = correspondence;

                Session[SessionCachePrefix + "CorrespondenceUnmodified"] = correspondence.Copy();

                #endregion
            } // Initial Page Load

            else   // Postback

            {
                correspondence = (Mercury.Client.Core.Reference.Correspondence)Session[SessionCachePrefix + "Correspondence"];
            }

            ApplySecurity();

            return;
        }