Exemple #1
0
        public JsonResult getSurveyResult(int surveyId, int userId)
        {
            SurveyForm        sur    = new SurveyForm();
            SurveyResultModel survey = new SurveyResultModel();
            ResultModel       result = new ResultModel();

            result.SurveyId = surveyId;
            result.UserId   = userId;
            result.results  = sur.getSurveyResult(surveyId, userId);

            // return result;
            return(Json(result, JsonRequestBehavior.AllowGet));


            //catch(Exception ex)
            //{
            //    return Json(ex.Message, JsonRequestBehavior.AllowGet);
            //}
        }
        public SurveyForm GetSurveyFormById(int id)
        {
            SurveyForm form = _dbContext.SurveyForms.Find(id);

            if (form == null)
            {
                return(null);
            }
            else
            {
                form.Questions = this._dbContext.SurveyQuestions.Where(ques => ques.SurveyFormId == form.SurveyFormId).ToList();
                form.Questions.ForEach(ques =>
                {
                    ques.Options = this._dbContext.SurveyOptions.Where(optn => optn.SurveyQuestionId == ques.Id).ToList();
                }
                                       );
                return(form);
            }
        }
Exemple #3
0
 public string AddUser(string Name, string Email, string SelectedSurvey)
 {
     try
     {
         SurveyForm sur = new SurveyForm();
         if (sur.AddUser(Name, Email, Int32.Parse(SelectedSurvey)) == true)
         {
             return("User Added Succesfully");
         }
         else
         {
             return("User have been already added for this Survey");
         }
     }
     catch (Exception ex)
     {
         //return ("There was some error in adding user");
         return(ex.Message);
     }
 }
        public void HomeController_SurveySubmitAction_RedirectToIndexView()
        {
            //Arrange
            SurveySqlDAL     mockDal    = new SurveySqlDAL(connectionString);
            SurveyController controller = new SurveyController();
            SurveyForm       model      = new SurveyForm()
            {
                ParkCode      = "gnp",
                EmailAddress  = "*****@*****.**",
                State         = "test",
                ActivityLevel = "test"
            };

            //Act
            mockDal.SubmitSurvey(model);
            RedirectToRouteResult result = controller.SurveySubmit(model) as RedirectToRouteResult;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Index", result.RouteValues["action"]);
        }
        public bool SubmitSurvey(SurveyForm survey)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(connectionString))
                {
                    conn.Open();

                    SqlCommand cmd = new SqlCommand(SQL_PostSurvey, conn);
                    cmd.Parameters.AddWithValue("@parkcode", survey.ParkCode);
                    cmd.Parameters.AddWithValue("@emailAddress", survey.EmailAddress);
                    cmd.Parameters.AddWithValue("@state", survey.State);
                    cmd.Parameters.AddWithValue("@activityLevel", survey.ActivityLevel);

                    int rowsAffected = cmd.ExecuteNonQuery();

                    return(rowsAffected > 0);
                }
            }
            catch (SqlException e)
            {
                throw;
            }
        }
Exemple #6
0
        private void BindSurvey(string surveyId)
        {
            SurveyForm survey = null;
            List <KeyValuePair <int, int> > questionAnswers = new List <KeyValuePair <int, int> >();

            using (ProjectTrackerContainer db = new ProjectTrackerContainer())
            {
                var questions = db.SurveyQuestions
                                .OrderBy(q => q.OrderId)
                                .Select(s => new { s.Id, s.Question })
                                .ToList();
                gvQuestion.DataSource = questions;
                gvQuestion.DataBind();

                var surveyDb = db.SurveyForms.FirstOrDefault(s => s.Id == surveyId);
                survey = surveyDb;

                var surveyAnswers = db.SurveyFormAnswers
                                    .Where(s => s.FormId == surveyId)
                                    .Select(s => new { s.QuestionId, s.OptionId });

                foreach (var sa in surveyAnswers)
                {
                    questionAnswers.Add(new KeyValuePair <int, int>(sa.QuestionId, sa.OptionId));
                }
            }

            if (survey != null && survey.Responded)
            {
                if (questionAnswers.Count > 0)
                {
                    foreach (GridViewRow row in gvQuestion.Rows)
                    {
                        Label lblId      = row.FindControl("lblId") as Label;
                        int   questionId = 0;
                        Int32.TryParse(lblId.Text, out questionId);

                        if (questionId > 0)
                        {
                            for (int i = 1; i < 9; i++)
                            {
                                string   chkName = "chk" + i.ToString();
                                CheckBox chkBox  = (row.FindControl(chkName) as CheckBox);
                                if (questionAnswers.Contains(new KeyValuePair <int, int>(questionId, i)))
                                {
                                    chkBox.Checked = true;
                                    continue;
                                }
                            }
                        }
                    }
                }

                txtComments.Text = survey.Comment;

                StringBuilder script = new StringBuilder();

                if (survey.Recommend != null)
                {
                    script.Append("<script>");

                    if ((bool)survey.Recommend)
                    {
                        script.Append("if (!document.getElementById('option1').checked){document.getElementById('option1').checked=true;} ");
                    }
                    else
                    {
                        script.Append("if (!document.getElementById('option2').checked){document.getElementById('option2').checked=true;} ");
                    }

                    script.Append("</script>");
                    ClientScript.RegisterStartupScript(GetType(), "Javascript", script.ToString());
                }

                //DisableUI();
            }
        }
Exemple #7
0
        private bool SaveSurvey(SurveyForm survey, ProjectTrackerContainer db)
        {
            bool saved = false;

            var questionAnswers = new List <KeyValuePair <int, int> >();

            foreach (GridViewRow row in gvQuestion.Rows)
            {
                Label lblId      = row.FindControl("lblId") as Label;
                int   questionId = 0;
                Int32.TryParse(lblId.Text, out questionId);

                if (questionId > 0)
                {
                    for (int i = 1; i < 9; i++)
                    {
                        string   chkName = "chk" + i.ToString();
                        CheckBox chkBox  = (row.FindControl(chkName) as CheckBox);
                        if (chkBox.Checked)
                        {
                            questionAnswers.Add(new KeyValuePair <int, int>(questionId, i));
                            continue;
                        }
                    }
                }
            }

            foreach (var qOption in questionAnswers)
            {
                SurveyFormAnswer fa = new SurveyFormAnswer()
                {
                    FormId     = survey.Id,
                    QuestionId = qOption.Key,
                    OptionId   = qOption.Value
                };

                db.SurveyFormAnswers.Add(fa);
            }

            string recommend = "No";

            if (Request.Form["options"] != null)
            {
                recommend = Request.Form["options"].ToString();
            }

            survey.Recommend = recommend == "Yes" ? true : false;
            survey.Comment   = txtComments.Text.Length > 500 ? txtComments.Text.Substring(0, 500) : txtComments.Text;

            survey.Responded   = true;
            survey.RespondDate = DateTime.Now;

            try
            {
                db.SaveChanges();
                saved = true;
            }
            catch (Exception ex)
            {
                throw new Exception("An Error Has Occurred. " + ex.Message);
            }

            return(saved);
        }
Exemple #8
0
 public SurveyForm PostNewSurveyForm([FromBody] SurveyForm surveyForm)
 {
     return(this.SurveyProvider.PostNewSurveyForm(surveyForm));
 }
Exemple #9
0
        public static Survey CreateSurveyFromForm(SurveyForm thisForm)
        {
            Survey survey = new Survey();

            survey.SurveyAnswers = new List <SurveyAnswer>();

            survey.SeqLNr = GetNewSeqLNr();
            survey.Dat    = DateTime.Now.Date;
            survey.Typ    = thisForm.Typ;
            int subnr = 0;

            switch (survey.Typ.ToLower())
            {
            case "hla":
                survey.TypDsc = "Hälsovårdskort";
                break;

            case "oha":
                survey.TypDsc = "Munvårdskort";
                break;
            }

            foreach (var q in thisForm.Questions)
            {
                subnr++;
                SurveyAnswer newAnswer = new SurveyAnswer();
                newAnswer.SeqLNr = survey.SeqLNr;
                newAnswer.SubNr  = subnr;

                newAnswer.Dsc     = q.Dsc;
                newAnswer.KeyWrd  = q.KeyWrd;
                newAnswer.Man     = q.Man;
                newAnswer.Multi   = q.Multi;
                newAnswer.OhaTyp  = q.OhaTyp;
                newAnswer.SelList = q.SelList;
                newAnswer.Sort    = q.Sort;
                newAnswer.SysVar  = q.SysVar;
                newAnswer.Txt     = q.Txt;

                switch (q.OhaTyp.ToLower())
                {
                case "sel":
                    newAnswer.PrmDec = q.Multi;
                    newAnswer.PrmChr = q.Dsc;
                    string[] parts = q.SelList.Split('¤');
                    if (parts.Length > 0)
                    {
                        for (int i = 0; i < parts.Length; i++)
                        {
                            newAnswer.PrmChr += "¤" + parts[i] + "|0";
                        }
                    }
                    break;

                case "int":
                    newAnswer.PrmChr = q.Dsc + "¤0";
                    break;

                case "chr":
                    newAnswer.PrmChr = q.Dsc + "¤";
                    break;

                case "top":
                    newAnswer.PrmChr = q.Dsc;
                    break;
                }

                survey.SurveyAnswers.Add(newAnswer);
            }

            return(survey);
        }
Exemple #10
0
 public IActionResult Success(SurveyForm newForm)
 {
     return(View("Submit", newForm));
 }
 public IActionResult Result(SurveyForm YourSurvey)
 {
     return(View(YourSurvey));
 }
 public IActionResult Registration(SurveyForm YourSurvey)
 {
     return(RedirectToAction("result", YourSurvey));
 }
Exemple #13
0
        public JsonResult GetSurveyLinksInfo()
        {
            SurveyForm sur = new SurveyForm();

            return(Json(sur.GetSurveyLinksInfo(), JsonRequestBehavior.AllowGet));
        }
Exemple #14
0
        public JsonResult GetRequiredQuestions(int surveyId)
        {
            SurveyForm sur = new SurveyForm();

            return(Json(sur.getRequiredQuestions(surveyId), JsonRequestBehavior.AllowGet));
        }
Exemple #15
0
 public int SaveSurvey(SurveyForm form)
 {
     return(SurveyDAO.Instance.Save(form));
 }