Exemplo n.º 1
0
    protected void ApproveButton_Click(object sender, EventArgs e)
    {
        bool isError = false;

        try
        {
            ServiceAccess                   serviceLoader = ServiceAccess.GetInstance();
            FarmService.FarmService         farmService   = serviceLoader.GetFarm();
            IList <FarmService.ContactInfo> contacts      = (IList <FarmService.ContactInfo>)Session["Contacts"];
            Session.Remove("Contacts");
            FarmService.FarmInfo farm = new FarmService.FarmInfo();
            farm.FarmName    = FarmNameTextBox.Text;
            farm.MailingPlan = new FarmService.MailingPlanInfo();
            farm.MailingPlan.MailingPlanId = int.Parse(MailingPlanDropDownList.SelectedValue);
            farm.LastModifyBy          = LoginUserId;
            farm.Plots                 = new FarmService.PlotInfo[1];
            farm.Plots[0]              = new FarmService.PlotInfo();
            farm.Plots[0].PlotId       = 0;
            farm.Plots[0].PlotName     = FarmNameTextBox.Text;
            farm.Plots[0].Contacts     = (FarmService.ContactInfo[])contacts;
            farm.Plots[0].LastModifyBy = LoginUserId;
            farm.UserId                = GetAgentId();
            farmService.CreateFarmPlot(farm);
        }
        catch (Exception exception)
        {
            if (exception.Message.Contains("No Contacts processed. Farm cannot be Empty."))
            {
                ErrorLiteral.Text = "No Contacts processed. Farm cannot be Empty.";
            }
            else
            {
                log.Error("UNKNOWN ERROR WHILE CREATING Farm:", exception);
                ErrorLiteral.Text = "UNKNOWN ERROR WHILE CREATING Farm. Please Contact Administrator";
            }
            isError = true;
        }
        if (!isError)
        {
            Response.Redirect("~/Members/FarmManagement.aspx");
        }
    }