예제 #1
0
    /// <summary>
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        UrlRedirectAdmin urlRedirectAdmin = new UrlRedirectAdmin();
        UrlRedirect urlRedirectEntity = new UrlRedirect();
        bool status = false;
        string oldSeoURL = "";
        bool activeInd = false;

        if (ItemId > 0)
        {
            urlRedirectEntity = urlRedirectAdmin.GetById(ItemId);
            oldSeoURL = urlRedirectEntity.OldUrl;
            activeInd = urlRedirectEntity.IsActive;
        }

        urlRedirectEntity.IsActive = chkIsActive.Checked;
        urlRedirectEntity.OldUrl = MakeUrl(txtOldUrl.Text.Trim());
        urlRedirectEntity.NewUrl = MakeUrl(txtNewUrl.Text.Trim());

        // create transaction
        TransactionManager tranManager = ConnectionScope.CreateTransaction();

        if (ItemId > 0)
        {
            status = urlRedirectAdmin.Update(urlRedirectEntity);
        }
        else
        {
            status = urlRedirectAdmin.Add(urlRedirectEntity);
        }

        if (status)
        {
            try
            {
                ZNodeSEOUrl seoUrl = new ZNodeSEOUrl();
                bool urlRedirectExists = urlRedirectAdmin.Exists(urlRedirectEntity.OldUrl, urlRedirectEntity.NewUrl, urlRedirectEntity.UrlRedirectID);

                if (ItemId > 0 && activeInd && !chkIsActive.Checked)
                {
                    status &= seoUrl.RemoveRedirectURL(oldSeoURL);
                }
                else if(chkIsActive.Checked && !urlRedirectExists)
                {
                    status &= seoUrl.AddRedirectUrl(oldSeoURL, urlRedirectEntity.OldUrl, urlRedirectEntity.NewUrl, chkIsActive.Checked);
                }
                else if(urlRedirectExists)
                {
                    status &= false;

                    // error occurred so rollback transaction
                    tranManager.Rollback();

                    lblMsg.Text = "Unable to update SEO Friendly URL. Please try again.";

                    return;
                }
            }
            catch
            {
                status = false;

                // error occurred so rollback transaction
                tranManager.Rollback();

                lblMsg.Text = "Unable to update SEO Friendly URL. Please try again.";

                return;
            }
        }

        if (status)
        {
            // Commit transaction
            tranManager.Commit();

            Response.Redirect(ListPageLink);
        }
        else
        {
            // error occurred so rollback transaction
            tranManager.Rollback();

            lblMsg.Text = "Unable to process your request.";
        }
    }