Beispiel #1
0
        public ActionResult GoTo(int id)
        {
            using (var context = new LeadGenContext())
            {
                var e = context.Events.Include("QuestionList").Include("QuestionList.QuestionChoices").Where(p => p.EventId == id).ToList();
                if (e.Any())
                {
                    return View("Index", e.First());
                }

                return RedirectToAction("Index", "Home");
            }
        }
Beispiel #2
0
        public ActionResult CommitQuestion(int EventId, string QuestionText, int QuestionType)
        {
            Question q = new Question();
            q.QuestionText = QuestionText;
            q.QuestionType = (short)QuestionType;

            if (q.QuestionType == (decimal)QuestionTypes.MultipleChoiceSelectOne || q.QuestionType == (decimal)QuestionTypes.MultipleChoiceSelectMany)
            {
                //q.QuestionChoices = new List<string>();
                var choices = Request.Form.AllKeys.Where(p => p.Contains("choice_"));
                q.QuestionChoices = new List<QuestionChoice>();

                foreach (var c in choices)
                {
                    string val = Request.Form[c];
                    if (!string.IsNullOrWhiteSpace(val))
                    {
                        q.QuestionChoices.Add(new QuestionChoice() { Text = val });
                    }
                }
            }

            using (var context = new LeadGenContext())
            {
                var events = context.Events.Where(p => p.EventId == EventId);
                if (!events.Any())
                    return RedirectToAction("Index");

                var firstEvent = events.First();

                q.QuestionNumber = firstEvent.QuestionList.Any() ? firstEvent.QuestionList.Max(p => p.QuestionNumber) + 1 : 1;

                if (firstEvent.QuestionList == null)
                    firstEvent.QuestionList = new List<Question>();

                firstEvent.QuestionList.Add(q);

                try
                {
                    context.SaveChanges();
                }
                catch (DbEntityValidationException entityValidationException)
                {
                    foreach (var ex in entityValidationException.EntityValidationErrors)
                        Debug.WriteLine(string.Format("Validation Exception: {0}", ex));
                }
            }

            return RedirectToAction("EventDetails", new { id = EventId });
        }
Beispiel #3
0
        public ActionResult AddEvent(Event model)
        {
            if (ModelState.IsValid)
            {
                using (var context = new LeadGenContext())
                {
                    context.Events.Add(model);
                    context.SaveChanges();
                }

                return RedirectToAction("EventDetails", "Admin", new { id = model.EventId });
            }
            return View(model);
        }
Beispiel #4
0
        public ActionResult AddQuestion(int id)
        {
            using (var context = new LeadGenContext())
            {
                // verify event
                var events = context.Events.Where(p => p.EventId == id);
                if (!events.Any())
                    return RedirectToAction("Index");

                ViewBag.EventName = events.First().EventName;
                ViewBag.EventId = id;

                return View(new Question());
            }
        }
Beispiel #5
0
        public ActionResult GetEventList()
        {
            using (var context = new LeadGenContext())
            {
                List<Event> events = context.Events.Where(p => p.EndDate > DateTime.Now).ToList();
                //List<EventViewModel> vm = events.Select(e => new EventViewModel(e)
                //                                                 {
                //                                                     URL = Url.Action("GoTo", "Event", new {id = e.EventId})
                //                                                 }).ToList();

                var vm = from e in events
                         select new
                                    {
                                        URL = Url.Action("GoTo", "Event", new { id = e.EventId }),
                                        e.EventId,
                                        e.EventName,
                                        e.StartDate,
                                        e.EndDate
                                    };

                return Json(vm, JsonRequestBehavior.AllowGet);
            }
        }
Beispiel #6
0
        public ActionResult MoveQuestionUp(int questionId, int eventId)
        {
            using (var context = new LeadGenContext())
            {
                Debug.WriteLine("--------");
                var origEvent = context.Events.FirstOrDefault(p => p.EventId == eventId);
                if (origEvent == null)
                    return Json(false);

                var questionA = origEvent.QuestionList.FirstOrDefault(p => p.QuestionId == questionId);
                if (questionA == null)
                    return Json(false);
                var questionNumberA = questionA.QuestionNumber;

                var questionB = origEvent.QuestionList.FirstOrDefault(p => p.QuestionNumber == questionNumberA - 1);
                if (questionB == null)
                    return Json(false);

                questionA.QuestionNumber = questionA.QuestionNumber - 1;
                questionB.QuestionNumber = questionB.QuestionNumber + 1;

                context.SaveChanges();

                return Json(true);
            }
        }
Beispiel #7
0
 public ActionResult Index()
 {
     using (var context = new LeadGenContext())
     {
         return View(context.Events.ToList());
     }
 }
Beispiel #8
0
        public ActionResult ExportResults(int id)
        {
            C1.C1Excel.C1XLBook book = new C1XLBook();
            book.Author = "Kevin Griffin";

            var sheet = book.Sheets[0];

            using (var context = new LeadGenContext())
            {
                // sheet 0, contact info
                sheet.Name = "Respondents";

                var responseEvents = context.Responses.Include("OriginalEvent").Include("Responses").Include("Responses.OriginalQuestion").Where(p => p.OriginalEvent.EventId == id);

                sheet[0, 0].Value = "First Name";
                sheet[0, 1].Value = "Last Name";
                sheet[0, 2].Value = "Email Address";
                sheet[0, 3].Value = "Zip Code";

                int currentRow = 1;
                foreach (var response in responseEvents)
                {
                    sheet[currentRow, 0].Value = response.FirstName;
                    sheet[currentRow, 1].Value = response.LastName;
                    sheet[currentRow, 2].Value = response.EmailAddress;
                    sheet[currentRow, 3].Value = response.ZipCode;
                    currentRow++;
                }

                sheet = book.Sheets.Add();
                sheet.Name = "Results";

                var results = new List<QuestionResult>();
                foreach (var e in responseEvents)
                {
                    foreach (var q in e.Responses.OrderBy(p => p.OriginalQuestion.QuestionId))
                    {
                        // is q in result list?
                        QuestionResponse q1 = q;
                        var questionResults = results.Where(p => p.QuestionText == q1.OriginalQuestion.QuestionText);
                        if (questionResults.Any())
                        {
                            // is answer in questionResult
                            var first = questionResults.First();
                            var answers = first.QuestionAnswers.Where(p => p.AnswerText == q1.Answer);
                            if (answers.Any())
                            {
                                var firstAnswer = answers.First();
                                firstAnswer.AnswerCount++;
                            }
                            else
                            {
                                first.QuestionAnswers.Add(new Answer() { AnswerText = q.Answer, AnswerCount = 1 });
                            }
                        }
                        else
                        {
                            results.Add(new QuestionResult
                            {
                                QuestionText = q.OriginalQuestion.QuestionText,
                                QuestionAnswers = new List<Answer>() { new Answer() { AnswerCount = 1, AnswerText = q.Answer } }
                            });
                        }
                    }
                }

                sheet[0, 0].Value = "Question Text";
                sheet[0, 1].Value = "Answer Count";
                sheet[0, 2].Value = "Answer Text";

                currentRow = 1;
                foreach (var questionResult in results)
                {
                    sheet[currentRow, 0].Value = questionResult.QuestionText;
                    currentRow++;
                    foreach (var answer in questionResult.QuestionAnswers)
                    {
                        sheet[currentRow, 1].Value = answer.AnswerCount;
                        sheet[currentRow, 2].Value = answer.AnswerText;
                        currentRow++;
                    }
                }

                sheet = book.Sheets.Add();
                sheet.Name = "Results per Attendee";

                sheet[0, 0].Value = "Attendee Name";
                sheet[0, 1].Value = "Question Text";
                sheet[0, 2].Value = "Answer Text";

                currentRow = 1;
                foreach (var response in context.Responses.Where(p => p.OriginalEvent.EventId == id).Include("Responses"))
                {
                    sheet[currentRow, 0].Value = string.Format("{0} {1}", response.FirstName, response.LastName);

                    foreach (var r in response.Responses)
                    {
                        sheet[currentRow, 1].Value = r.OriginalQuestion.QuestionText;
                        sheet[currentRow, 2].Value = r.Answer;
                        currentRow++;
                    }

                }
            }

            var tempFile = System.IO.Path.GetTempFileName();
            book.Save(tempFile);

            return File(tempFile, "application/vnd.ms-excel", "event.xls");
        }
Beispiel #9
0
        public ActionResult EventResults(int id)
        {
            using (var context = new LeadGenContext())
            {
                var responseEvents = context.Responses.Include("OriginalEvent").Include("Responses").Include("Responses.OriginalQuestion").Where(p => p.OriginalEvent.EventId == id);

                if (!responseEvents.Any())
                    return RedirectToAction("Index", "Admin");

                ViewBag.EventId = id;

                var results = new List<QuestionResult>();
                ViewBag.EventTitle = responseEvents.First().OriginalEvent.EventName;

                ResultModel model = new ResultModel { Respondants = new List<Respondant>() };
                foreach (var e in responseEvents)
                {
                    model.Respondants.Add(new Respondant()
                                              {
                                                  EmailAddress = e.EmailAddress,
                                                  FirstName = e.FirstName,
                                                  LastName = e.LastName,
                                                  ZipCode = e.ZipCode
                                              });

                    foreach (var q in e.Responses.OrderBy(p => p.OriginalQuestion.QuestionId))
                    {
                        // is q in result list?
                        QuestionResponse q1 = q;
                        var questionResults = results.Where(p => p.QuestionText == q1.OriginalQuestion.QuestionText);
                        if (questionResults.Any())
                        {
                            // is answer in questionResult
                            var first = questionResults.First();
                            var answers = first.QuestionAnswers.Where(p => p.AnswerText == q1.Answer);
                            if (answers.Any())
                            {
                                var firstAnswer = answers.First();
                                firstAnswer.AnswerCount++;
                            }
                            else
                            {
                                first.QuestionAnswers.Add(new Answer() { AnswerText = q.Answer, AnswerCount = 1 });
                            }
                        }
                        else
                        {
                            results.Add(new QuestionResult
                                            {
                                                QuestionText = q.OriginalQuestion.QuestionText,
                                                QuestionAnswers = new List<Answer>() { new Answer() { AnswerCount = 1, AnswerText = q.Answer } }
                                            });
                        }
                    }
                }
                model.Results = results;

                return View(model);
            }
        }
Beispiel #10
0
        public ActionResult EventDetails(int id)
        {
            using (var context = new LeadGenContext())
            {
                var events = context.Events.Include("QuestionList").Where(p => p.EventId == id);
                if (!events.Any())
                    return RedirectToAction("Index");

                Event first = events.First();
                return View(first);
            }
        }
Beispiel #11
0
        public ActionResult DeleteEvent(int id)
        {
            using (var context = new LeadGenContext())
            {
                var events = context.Events.Where(p => p.EventId == id);
                if (!events.Any())
                    return RedirectToAction("Index");

                Event e = events.First();

                // delete all questionlist
                // delete all questionchoices
                // delete all eventresponses
                // delete all questionresponses

                context.Events.Remove(e);
                context.SaveChanges();
            }

            return RedirectToAction("Index", "Admin");
        }
Beispiel #12
0
        public ActionResult SubmitResults(int EventId)
        {
            using (var context = new LeadGenContext())
            {
                var events = context.Events.Where(p => p.EventId == EventId);

                if (events.Any())
                {
                    EventResponse eventResponse = new EventResponse();
                    eventResponse.OriginalEvent = events.First();
                    eventResponse.Responses = new Collection<QuestionResponse>();

                    foreach (var e in Request.Form.AllKeys)
                    {
                        string formValue = Request.Form[e];
                        Debug.WriteLine(string.Format("Form Key: {0} == {1}", e, formValue));

                        if (e.Contains("EventId") || e.Contains("button")) // don't care about these
                            continue;

                        var splitKey = e.Split('_');

                        switch (splitKey[1])
                        {
                            case "firstName":
                                eventResponse.FirstName = formValue;
                                continue;
                            case "lastName":
                                eventResponse.LastName = formValue;
                                continue;
                            case "email":
                                eventResponse.EmailAddress = formValue;
                                continue;
                            case "zipCode":
                                eventResponse.ZipCode = formValue;
                                continue;
                        }

                        var questionId = int.Parse(splitKey[1]);

                        var question = context.Questions.Where(p => p.QuestionId == questionId);
                        if (!question.Any())
                            throw new Exception("Question not found.");

                        Question originalQuestion = question.First();
                        if (originalQuestion.QuestionType == (short)QuestionTypes.MultipleChoiceSelectMany)
                        {
                            var splitAnswers = formValue.Split(',');
                            foreach (var a in splitAnswers)
                            {
                                eventResponse.Responses.Add(new QuestionResponse()
                                {
                                    Answer = a,
                                    OriginalQuestion = originalQuestion
                                });
                            }
                        }
                        else
                        {
                            eventResponse.Responses.Add(new QuestionResponse()
                                                            {
                                                                Answer = formValue,
                                                                OriginalQuestion = originalQuestion
                                                            });
                        }

                    }

                    context.Responses.Add(eventResponse);

                    context.SaveChanges();
                }
                else
                {
                    throw new Exception("Event not found.");
                }
            }

            return RedirectToAction("Thanks", "Event");
        }