Пример #1
0
    /// <summary>
    /// Event triggered when a command button is clicked on the grid
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void uxGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        // Convert the row index stored in the CommandArgument
        // property to an Integer.
        int index = Convert.ToInt32(e.CommandArgument);

        // Get the values from the appropriate
        // cell in the GridView control.
        GridViewRow selectedRow = uxGrid.Rows[index];

        TableCell Idcell = selectedRow.Cells[0];
        string Id = Idcell.Text;

        if (e.CommandName == "Edit")
        {
            Response.Redirect(EditPageLink + Id);
        }
        else if (e.CommandName == "Delete")
        {
            UrlRedirectAdmin urlRedirectAdmin = new UrlRedirectAdmin();
            UrlRedirect urlRedirect = urlRedirectAdmin.GetById(int.Parse(Id));

            bool status = urlRedirectAdmin.Delete(int.Parse(Id));

            if (status)
            {
                if (urlRedirect != null)
                {
                    ZNodeSEOUrl seoUrl = new ZNodeSEOUrl();
                    seoUrl.RemoveRedirectURL(urlRedirect.OldUrl);
                }

                Bind();
            }
        }
    }
Пример #2
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.";
        }
    }