Esempio n. 1
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);
        }
Esempio n. 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 });
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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");
        }
Esempio n. 5
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");
        }