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.PlotInfo plot = new FarmService.PlotInfo();

            plot.PlotId       = 0;
            plot.PlotName     = PlotNameTextBox.Text;
            plot.FarmId       = Convert.ToInt32(FarmIdHiddenField.Value.ToString());
            plot.Contacts     = (FarmService.ContactInfo[])contacts;
            plot.LastModifyBy = LoginUserId;
            farmService.CreatePlot(plot);
        }
        catch (Exception exception)
        {
            if (exception.Message.Contains("Plot Name already in use. Please provide a new Plot Name"))
            {
                ErrorLiteral.Text = "Plot Name already in use. Please provide a new Plot Name";
            }
            else if (exception.Message.Contains("No Contacts processed. Plot cannot be Empty."))
            {
                ErrorLiteral.Text = "No Contacts processed. Plot cannot be Empty.";
            }
            else
            {
                ErrorLiteral.Text = "UNKNOWN ERROR WHILE CREATING A PLOT. Please Contact Administrator";
                log.Error("UNKNOWN ERROR WHILE CREATING A PLOT:", exception);
            }
            isError = true;
        }
        if (!isError)
        {
            Response.Redirect("~/Members/ViewFarm.aspx?farmId=" + Request.QueryString["farmId"]);
        }
    }