Example #1
0
        public ActionResult Approve(Survey survey)
        {
            try
            {
                if (Session["UserAccountID"] == null)
                    return RedirectToAction("Validate", "Login");
                User user = (User)Session["User"];
                ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"]));
                if (user.IsAdmin)
                    ViewData["txtIsAdmin"] = "true";
                else
                    ViewData["txtIsAdmin"] = "false";

                if (ModelState.IsValid)
                {
                    // Set NULLs to Empty Strings
                    survey = FillNulls(survey);

                    survey.IsApproved = true;
                    repository.UpdateSurvey(survey);

                    CommonMethods.CreateActivityLog((User)Session["User"], "Survey", "Approve",
                                                    "Approved survey '" + survey.SurveyName + "' - ID: " + survey.SurveyID.ToString());

                    return RedirectToAction("Index");
                }

                return View(survey);
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("Survey", "Approve POST", ex.Message);
                return RedirectToAction("Index", "ApplicationError");
            }
        }
Example #2
0
        private Survey FillNulls(Survey survey)
        {
            if (survey.SurveyDescription == null) survey.SurveyDescription = String.Empty;

            return survey;
        }
Example #3
0
        private string ValidateInput(Survey survey)
        {
            if (survey.AccountID == 0)
                return "Account ID is not valid.";

            if (String.IsNullOrEmpty(survey.SurveyName))
                return "Survey Name is required.";

            if (survey.SurveyImageID == 0)
                return "You must select a survey image.";

            return String.Empty;
        }
Example #4
0
        private Survey CreateNewSurvey()
        {
            Survey survey = new Survey();
            survey.SurveyID = 0;
            survey.AccountID = 0;
            survey.SurveyName = String.Empty;
            survey.SurveyDescription = String.Empty;
            survey.IsApproved = false;
            survey.IsActive = true;

            return survey;
        }
Example #5
0
        private string BuildSurveyTableNoLinks(Survey survey)
        {
            try
            {
                StringBuilder sb = new StringBuilder();

                string root = Request.Url.OriginalString.Substring(0, Request.Url.OriginalString.ToLower().LastIndexOf("/survey/"));
                if (!root.EndsWith("/")) root += "/";

                sb.AppendLine("<table style=\"border-spacing:0;border-collapse:collapse;\" class=\"surveytable\">");
                sb.AppendLine("<tr class=\"surveyrow\">");
                sb.AppendLine("<td class=\"gridtext\">" + survey.SurveyName + "</td>");
                sb.AppendLine("<td class=\"gridtext\" style=\"width:110px;\"></td>");
                sb.AppendLine("<td class=\"gridtext\" style=\"width:25px;\"></td>");
                sb.AppendLine("<td class=\"gridtext\" style=\"width:45px;\"></td>");
                sb.AppendLine("<td class=\"gridtext\" style=\"width:35px;\"></td>");
                sb.AppendLine("<td class=\"gridtext\" style=\"width:55px;\"></td>");
                sb.AppendLine("</tr>");

                // Loop through each question and question option
                ISurveyQuestionRepository qrep = new EntitySurveyQuestionRepository();
                ISurveyQuestionOptionRepository orep = new EntitySurveyQuestionOptionRepository();
                List<SurveyQuestion> questions = qrep.GetSurveyQuestions(survey.SurveyID).ToList();

                foreach (SurveyQuestion question in questions)
                {
                    sb.AppendLine("<tr class=\"questionrow\">");
                    string selectionmode = " (Single Select)";
                    if (question.AllowMultiSelect) selectionmode = " (Multi Select)";
                    sb.AppendLine("<td class=\"gridtext\">" + question.SurveyQuestionText + selectionmode + "</td>");
                    sb.AppendLine("<td class=\"gridtext\"></td>");
                    sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>");
                    sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>");
                    sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>");
                    sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>");
                    sb.AppendLine("</tr>");

                    // Loop through each question option
                    List<SurveyQuestionOption> options = orep.GetSurveyQuestionOptions(question.SurveyQuestionID).ToList();
                    foreach (SurveyQuestionOption option in options)
                    {
                        sb.AppendLine("<tr class=\"optionrow\">");
                        sb.AppendLine("<td class=\"gridtext\" style=\"padding-left:15px;\">" + option.SurveyQuestionOptionText + "</td>");
                        sb.AppendLine("<td class=\"gridtext\"></td>");
                        sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>");
                        sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>");
                        sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>");
                        sb.AppendLine("<td class=\"gridtext\" style=\"text-align:center;\"></td>");
                        sb.AppendLine("</tr>");
                    }
                }

                sb.Append("</table>");

                return sb.ToString();
            }
            catch { return String.Empty; }
        }
Example #6
0
        public ActionResult Edit(Survey survey)
        {
            try
            {
                if (Session["UserAccountID"] == null)
                    return RedirectToAction("Validate", "Login");
                User user = (User)Session["User"];
                ViewData["LoginInfo"] = Utility.BuildUserAccountString(user.Username, Convert.ToString(Session["UserAccountName"]));
                if (user.IsAdmin)
                    ViewData["txtIsAdmin"] = "true";
                else
                    ViewData["txtIsAdmin"] = "false";

                if (ModelState.IsValid)
                {
                    // Set NULLs to Empty Strings
                    survey = FillNulls(survey);

                    IImageRepository imgrep = new EntityImageRepository();
                    Image img = imgrep.GetImageByGuid(Request.Form["lstImage"]);
                    if (img != null)
                        survey.SurveyImageID = img.ImageID;
                    else
                        survey.SurveyImageID = 0;

                    string validation = ValidateInput(survey);
                    if (!String.IsNullOrEmpty(validation))
                    {
                        ViewData["ValidationMessage"] = validation;
                        ViewData["ImageList"] = new SelectList(BuildImageList(Request.Form["lstImage"]), "Value", "Text", Request.Form["lstImage"]);
                        ViewData["ImageUrl"] = selectedfile;
                        ViewData["ImageFolder"] = ConfigurationManager.AppSettings["MediaRootFolder"] + Convert.ToString(Session["UserAccountID"]) + @"/Images/";

                        ViewData["SurveyTable"] = BuildSurveyTable(survey);
                        return View(survey);
                    }

                    repository.UpdateSurvey(survey);

                    CommonMethods.CreateActivityLog((User)Session["User"], "Survey", "Edit",
                                                    "Edited survey '" + survey.SurveyName + "' - ID: " + survey.SurveyID.ToString());

                    return RedirectToAction("Index");
                }

                return View(survey);
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("Survey", "Edit POST", ex.Message);
                return RedirectToAction("Index", "ApplicationError");
            }
        }
 public void CreateSurvey(Survey survey)
 {
     db.Surveys.Add(survey);
     db.SaveChanges();
 }
 public void UpdateSurvey(Survey survey)
 {
     db.Entry(survey).State = EntityState.Modified;
     db.SaveChanges();
 }