コード例 #1
0
        public void DeleteSurveyQuestion(SurveyQuestion question)
        {
            // Build the query
            var query = from surveyquestion in db.SurveyQuestions
                        select surveyquestion;

            query = query.Where(sqs => sqs.SurveyID.Equals(question.SurveyID));
            query = query.OrderBy("SortOrder", false);

            List<SurveyQuestion> surveyquestions = query.ToList();

            bool found = false;
            foreach (SurveyQuestion sq in surveyquestions)
            {
                if (found)
                {
                    sq.SortOrder -= 1;
                    db.Entry(sq).State = EntityState.Modified;
                }
                if (sq.SurveyQuestionID == question.SurveyQuestionID)
                {
                    found = true;
                    db.SurveyQuestions.Remove(sq);
                }
            }

            db.SaveChanges();
        }
コード例 #2
0
        public void CreateSurveyQuestion(SurveyQuestion question)
        {
            // Get the maximum sort order
            var query = from surveyquestion in db.SurveyQuestions
                        select surveyquestion;

            query = query.Where(sqs => sqs.SurveyID.Equals(question.SurveyID));
            query = query.OrderBy("SortOrder", true);

            List<SurveyQuestion> surveyquestions = query.ToList();

            int maxsortorder = 0;
            if (surveyquestions.Count > 0)
                maxsortorder = surveyquestions[0].SortOrder;

            question.SortOrder = maxsortorder + 1;
            db.SurveyQuestions.Add(question);
            db.SaveChanges();
        }
コード例 #3
0
        public ActionResult Create(int id, SurveyQuestion surveyquestion)
        {
            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)
                {
                    surveyquestion.SurveyID = id;
                    // Note: Proper sort order is applied in the repository

                    string validation = ValidateInput(surveyquestion);
                    if (!String.IsNullOrEmpty(validation))
                    {
                        ViewData["ValidationMessage"] = validation;
                        return View(surveyquestion);
                    }
                    else
                    {
                        repository.CreateSurveyQuestion(surveyquestion);

                        CommonMethods.CreateActivityLog((User)Session["User"], "SurveyQuestion", "Add",
                            "Added survey question '" + surveyquestion.SurveyQuestionText + "' - ID: " + surveyquestion.SurveyQuestionID.ToString());

                        return RedirectToAction("Edit", "Survey", new { id = surveyquestion.SurveyID });
                    }
                }
                return View(surveyquestion);
            }
            catch (Exception ex)
            {
                Helpers.SetupApplicationError("SurveyQuestion", "Create POST", ex.Message);
                return RedirectToAction("Index", "ApplicationError");
            }
        }
コード例 #4
0
        public void MoveSurveyQuestion(SurveyQuestion question, bool ismoveup)
        {
            var query = from surveyquestion in db.SurveyQuestions
                        select surveyquestion;
            query = query.Where(sqs => sqs.SurveyID.Equals(question.SurveyID));
            query = query.OrderBy("SortOrder", false);

            List<SurveyQuestion> surveyquestions = query.ToList();

            // Get the current and max sort orders
            int currentsortorder = question.SortOrder;
            int maxsortorder = 1;
            foreach (SurveyQuestion sq in surveyquestions)
            {
                if (sq.SortOrder > maxsortorder)
                    maxsortorder = sq.SortOrder;
            }

            // Adjust the appropriate sort orders
            foreach (SurveyQuestion sq in surveyquestions)
            {
                if (ismoveup)
                {
                    if (sq.SurveyQuestionID == question.SurveyQuestionID) // move current question up
                    {
                        if (currentsortorder > 1)
                            question.SortOrder -= 1;
                    }
                    else // find the previous item and increment it
                    {
                        if (sq.SortOrder == currentsortorder - 1)
                        {
                            sq.SortOrder += 1;
                            db.Entry(sq).State = EntityState.Modified;
                        }
                    }
                }
                else
                {
                    if (sq.SurveyQuestionID == question.SurveyQuestionID) // move current question down
                    {
                        if (currentsortorder < maxsortorder)
                            question.SortOrder += 1;
                    }
                    else // find the next item and decrement it
                    {
                        if (sq.SortOrder == currentsortorder + 1)
                        {
                            sq.SortOrder -= 1;
                            db.Entry(sq).State = EntityState.Modified;
                        }
                    }
                }
            }

            db.SaveChanges();
        }
コード例 #5
0
 public void UpdateSurveyQuestion(SurveyQuestion surveyquestion)
 {
     db.Entry(surveyquestion).State = EntityState.Modified;
     db.SaveChanges();
 }
コード例 #6
0
        private string ValidateInput(SurveyQuestion surveyquestion)
        {
            if (surveyquestion.SurveyID == 0)
                return "Survey ID is not valid.";

            if (String.IsNullOrEmpty(surveyquestion.SurveyQuestionText))
                return "Survey Question Text is required.";

            return String.Empty;
        }
コード例 #7
0
        //
        // Support Methods
        private SurveyQuestion CreateNewSurveyQuestion(int id)
        {
            SurveyQuestion surveyquestion = new SurveyQuestion();
            surveyquestion.SurveyQuestionID = 0;
            surveyquestion.SurveyID = id;
            surveyquestion.SurveyQuestionText = String.Empty;
            surveyquestion.AllowMultiSelect = false;
            surveyquestion.SortOrder = 1;

            return surveyquestion;
        }