Example #1
0
    protected void RestoreContactButton_Click(object sender, EventArgs e)
    {
        bool jumpError = false;

        try
        {
            ServiceAccess           serviceLoader = ServiceAccess.GetInstance();
            FarmService.FarmService farmService   = serviceLoader.GetFarm();
            int plotId = int.Parse(PlotIdHiddenField.Value.ToString());

            for (int i = 0; i < ContactListGridView.Rows.Count; i++)
            {
                GridViewRow row       = ContactListGridView.Rows[i];
                bool        isChecked = ((CheckBox)row.FindControl("ContactIdCheckBox")).Checked;
                if (isChecked)
                {
                    Int64 contactId = Int64.Parse(((CheckBox)row.FindControl("ContactIdCheckBox")).ToolTip);
                    farmService.RestoreContact(contactId, LoginUserId);
                }
            }

            FarmService.ContactInfo[] contacts = farmService.GetArchivedContactListForPlot(plotId);

            if (contacts.Length == 0)
            {
                Response.Redirect("~/Members/ArchivedPlotList.aspx");
            }
            else
            {
                //Getting Archived Plot Header Details
                FarmService.PlotInfo plot = farmService.GetArchivedPlotSummaryDetails(plotId);

                //Getting Parent Farm Details
                FarmService.FarmInfo farm = farmService.GetArchivedFarmSummaryDetails(plot.FarmId);

                PlotNameLabel.Text     = farm.FarmName + " / " + plot.PlotName;
                ContactCountLabel.Text = plot.ContactCount.ToString();
                CreateDateLabel.Text   = plot.CreateDate.ToShortDateString();

                ContactListGridView.DataSource = contacts;
                ContactListGridView.DataBind();
            }
        }
        catch (Exception exception)
        {
            log.Error("UNKNOWN ERROR WHILE RESTORING CONTACT:", exception);
            if (exception.Message.Contains("Parent Plot / Farm is not active. Contact cannot be restored."))
            {
                MessageLiteral.Text = "Parent Plot / Farm is not active. Contact cannot be restored.";
            }
            else
            {
                MessageLiteral.Text = "UNKNOWN ERROR: Please Contact Administrator";
                jumpError           = true;
            }
        }
        if (jumpError)
        {
            Response.Redirect("~/Members/ArchivedPlotList.aspx?farmId=" + FarmIdHiddenField.Value.ToString());
        }
    }