Beispiel #1
0
        public ActionResult Index()
        {
            countAllSurvey         = db.Surveys.Count();
            countAllSurveyComplete = db.Surveys.Where(c => c.Status == SurveyStatus.DONE).Count();
            AllSurvey allSurvey = db.Surveys.Where(c => c.UpdateDate > localDate).FirstOrDefault();

            if (allSurvey != null)
            {
                nextSurvey = allSurvey;
            }

            if (User.Identity.GetUserId() != null)
            {
                var uid   = User.Identity.GetUserId();
                var count = db.Account_answers.Where(a => a.Id == uid).GroupBy(a => a.SurveyId).Count();
                countAllSurveyAnswered = count;
            }
            else
            {
                countAllSurveyAnswered = 0;
            }
            ViewBag.NextSurvey        = nextSurvey;
            ViewBag.AllSurvey         = countAllSurvey;
            ViewBag.AllSurveyAnswered = countAllSurveyAnswered;
            ViewBag.AllSurveyComplete = countAllSurveyComplete;
            return(View());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            AllSurvey allSurvey = db.Surveys.Find(id);

            db.Surveys.Remove(allSurvey);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "SurveyId,Title,CreateDate,UpdateDate,Description,Status")] AllSurvey allSurvey)
 {
     if (ModelState.IsValid)
     {
         db.Entry(allSurvey).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(allSurvey));
 }
        // GET: AllSurveys/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AllSurvey allSurvey = db.Surveys.Find(id);

            if (allSurvey == null)
            {
                return(HttpNotFound());
            }
            return(View(allSurvey));
        }
        public ActionResult Create([Bind(Include = "SurveyId,Title,CreateDate,UpdateDate,Description,Status")] AllSurvey allSurvey)
        {
            if (ModelState.IsValid)
            {
                allSurvey.Status     = SurveyStatus.NOT_HAPPENNING_YET;
                allSurvey.CreateDate = DateTime.Now;
                allSurvey.UpdateDate = DateTime.Now;
                db.Surveys.Add(allSurvey);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(allSurvey));
        }
Beispiel #6
0
        public ActionResult SaveAnswer()
        {
            var       currentSurveyId = HttpContext.Request.Form["currentsurvey"];
            AllSurvey survey          = db.Surveys.Where(i => i.SurveyId.ToString() == currentSurveyId).FirstOrDefault();
            var       accountId       = User.Identity.GetUserId();

            foreach (var item in survey.Questions)
            {
                if (item.Type == 0)
                {
                    var           a      = HttpContext.Request.Form[item.Id.ToString()];
                    int           qId    = db.Question_answers.Where(q => q.QuestionId == item.Id).ToList().Where(d => d.Answer == a).FirstOrDefault().QuestionAnswerId;
                    AccountAnswer answer = new AccountAnswer
                    {
                        SurveyId         = survey.SurveyId,
                        Id               = accountId,
                        QuestionAnswerId = qId,
                        Status           = 1,
                        Description      = HttpContext.Request.Form[item.Id.ToString()]
                    };
                    db.Account_answers.Add(answer);
                }

                if (item.Type == 1)
                {
                    string        a      = HttpContext.Request.Form[item.Id.ToString()];
                    int           qId    = db.Question_answers.Where(q => q.QuestionId == item.Id).ToList().Where(d => d.Answer == a).FirstOrDefault().QuestionAnswerId;
                    AccountAnswer answer = new AccountAnswer
                    {
                        SurveyId         = survey.SurveyId,
                        Id               = accountId,
                        QuestionAnswerId = qId,
                        Status           = 1,
                        Description      = HttpContext.Request.Form[item.Id.ToString()]
                    };
                    db.Account_answers.Add(answer);
                }
                if (item.Type == 2)
                {
                    List <String> listAnswer = HttpContext.Request.Form[item.Id.ToString()].Split(',').ToList();

                    foreach (var a in listAnswer)
                    {
                        int           qId    = db.Question_answers.Where(q => q.QuestionId == item.Id).ToList().Where(d => d.Answer == a).FirstOrDefault().QuestionAnswerId;
                        AccountAnswer answer = new AccountAnswer
                        {
                            SurveyId         = survey.SurveyId,
                            Id               = accountId,
                            QuestionAnswerId = qId,
                            Status           = 1,
                            Description      = a
                        };
                        db.Account_answers.Add(answer);
                    }
                }
                if (item.Type == 3)
                {
                    List <String> listAnswer = HttpContext.Request.Form[item.Id.ToString()].Split(',').ToList();
                    if (listAnswer[0] == "Other")
                    {
                        int           qId    = db.Question_answers.Where(q => q.QuestionId == item.Id).ToList().Where(d => d.Answer == "Other").FirstOrDefault().QuestionAnswerId;
                        AccountAnswer answer = new AccountAnswer
                        {
                            SurveyId         = survey.SurveyId,
                            Id               = accountId,
                            QuestionAnswerId = qId,
                            Status           = 1,
                            Description      = listAnswer[1]
                        };
                        db.Account_answers.Add(answer);
                    }
                    if (listAnswer[0] != "Other")
                    {
                        var           des    = listAnswer[0];
                        int           qId    = db.Question_answers.Where(q => q.QuestionId == item.Id).ToList().Where(d => d.Answer == des).FirstOrDefault().QuestionAnswerId;
                        AccountAnswer answer = new AccountAnswer
                        {
                            SurveyId         = survey.SurveyId,
                            Id               = accountId,
                            QuestionAnswerId = qId,
                            Status           = 1,
                            Description      = des
                        };
                        db.Account_answers.Add(answer);
                    }
                }
                if (item.Type == 4)
                {
                    int           qId    = db.Question_answers.Where(q => q.QuestionId == item.Id).ToList().Where(d => d.Answer == "Essay").FirstOrDefault().QuestionAnswerId;
                    AccountAnswer answer = new AccountAnswer
                    {
                        SurveyId         = survey.SurveyId,
                        Id               = accountId,
                        QuestionAnswerId = qId,
                        Status           = 1,
                        Description      = HttpContext.Request.Form[item.Id.ToString()]
                    };
                    db.Account_answers.Add(answer);
                }
                db.SaveChanges();
            }
            return(Redirect("~/Home/Survey"));
        }