Exemplo n.º 1
0
    protected void JoinBTN_Click(object sender, EventArgs e)
    {
        //only validate if user has agreed to terms
        if (consentCheck.Checked)
        {
            DateTime defaultTime = Convert.ToDateTime("01-01-1800 12:00:00");

            CSS RequestDirector = new CSS();

            //check all open events to match event Key
            //return Event ID

            //get event info for key input
            Event currentEvent = new Event();
            currentEvent.EventID         = ((Event)Session["Event"]).EventID;
            currentEvent                 = RequestDirector.GetEvent(currentEvent);
            currentEvent.CustomQuestions = RequestDirector.GetQuestions(currentEvent.EventID);

            //check if event key exists
            if (currentEvent.EventKey != default(string))
            {
                //if event end time is not default value, event is over.  Can not join
                if (currentEvent.EventKey != "ZZZZ")
                {
                    //create new evaluator
                    Evaluator activeEvaluator = new Evaluator();

                    //get name if supplied
                    if (tbName.Text == "")
                    {
                        activeEvaluator.Name = "Default";
                    }
                    else
                    {
                        activeEvaluator.Name = tbName.Text;
                    }

                    //get criteria if selected
                    if (DDLCrit.Items.Count > 0)
                    {
                        activeEvaluator.Criteria = DDLCrit.SelectedValue;
                    }
                    else
                    {
                        activeEvaluator.Criteria = "Overall Quality";
                    }

                    activeEvaluator = RequestDirector.CreateEvaluator(activeEvaluator);

                    foreach (Question q in currentEvent.CustomQuestions)
                    {
                        q.EvaluatorID = activeEvaluator.EvaluatorID;

                        string responseTBID = string.Format("tb{0}", q.QID);

                        TextBox tb = (TextBox)(PanelQuestions.FindControl(responseTBID));

                        q.ResponseText = tb.Text;

                        RequestDirector.AddResponse(q);
                    }

                    //redirect to evaluate page if evaluator is created
                    if (activeEvaluator.EvaluatorID != default(int))
                    {
                        //create consent cookie if there isn't one
                        var consentCookie = Request.Cookies["ConsentCookie"];

                        if (consentCookie == null)
                        {
                            HttpCookie newConsent = new HttpCookie("ConsentCookie", "true");

                            //set cookie to expire in 100 days
                            newConsent.Expires = DateTime.UtcNow.AddDays(100);

                            Response.Cookies.Add(newConsent);
                        }

                        //Evaluation eval = new Evaluation(defaultTime, 999, activeEvaluator.EvaluatorID, currentEvent.EventID);
                        Evaluation eval = new Evaluation(DateTime.Now.ToUniversalTime(), 999, activeEvaluator.EvaluatorID, currentEvent.EventID);

                        RequestDirector.AddEvaluation(eval);

                        Session["Event"]     = currentEvent;
                        Session["Evaluator"] = activeEvaluator;
                        Response.Redirect("EvaluateEvent.aspx");
                    }
                    else
                    {
                        //error creating evaluator
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('There was an error joining this event.')", true);
                    }
                }
                else
                {
                }
            }
            else
            {
            }
        }
        else
        {
            consentCheck.ForeColor = System.Drawing.Color.Red;
        }
    }