public void AddGroup(int pollID, String name)
 {
     var pollRepository = new PollRepository(session);
     ParticipantGroup group = new ParticipantGroup(name);
     pollRepository.GetPollByID(pollID).groups.Add(group);
     session.SaveOrUpdate(group);
 }
 public PollReportViewModel(int pollID, String name, IList<Participant> participants)
 {
     var pollRepository = new PollRepository(NHibernateHelper.GetCurrentSession());
     this.pollID = pollID;
     this.name = name;
     this.participants = participants;
     this.include = true;
     this.poll = pollRepository.GetPollByID(pollID);
     this.selectedEntities = new List<Entity>();
 }
 public IList<Entity> GetEndEntities(int pollID)
 {
     var pollRepository = new PollRepository(session);
     var all = pollRepository.GetPollByID(pollID).entities;
     var entities = (from item1 in all from item2 in all
                     where item2.parent!=null && item1.entityID == item2.parent.entityID
                     select item1);
     var answer = (from item in all where !(entities.Contains(item)) select item);
     return answer.ToList<Entity>();
 }
 public PollReportViewModel(int pollID, String name, IList<Question> questions, IDictionary<Question, IDictionary<String, int>> responses)
 {
     var pollRepository = new PollRepository(NHibernateHelper.GetCurrentSession());
     this.pollID = pollID;
     this.name = name;
     this.questions = questions;
     this.responses = responses;
     this.poll = pollRepository.GetPollByID(pollID);
     this.include = true;
     this.selectedEntities = new List<Entity>();
 }
 public PollReportViewModel(int pollID, String name)
 {
     var pollRepository = new PollRepository(NHibernateHelper.GetCurrentSession());
     this.pollID = pollID;
     this.name = name;
     this.poll = pollRepository.GetPollByID(pollID);
     this.include = true;
     uri = "../../resources/MyFirstPDF" + Helpers.CodeFile1.FILE + ".pdf";
     this.field = new ParticipantField();
     this.selectedEntities = new List<Entity>();
 }
 public IList<int[]> GetAllQuestionResults(int pollID)
 {
     var pollRepository = new PollRepository(session);
     var poll = pollRepository.GetPollByID(pollID);
     var questions = poll.questions.Where(m => m.deletionTime == null);
     List<int[]> questionResults = new List<int[]>();
     foreach (var question in questions)
     {
         questionResults.Add(GetQuestionResults(question.questionID));
     }
     return questionResults;
 }
        public String[] GetNextGridResponses(int pollID)
        {
            var pollRepository = new PollRepository(session);
            var poll = pollRepository.GetPollByID(pollID);
            var keypads = from item in poll.gridResponses
                          select item.DeviceID;
            var responses = new List<String>();
            responses.AddRange(keypads);
            poll.gridResponses = null;
            pollRepository.UpdatePoll(poll);

            return responses.ToArray<String>();
        }
 public PollReportViewModel(int pollID, String name, IList<Question> questions, IDictionary<Question, IDictionary<String, int>> responses, ParticipantField field, bool include, String[] tick)
 {
     var pollRepository = new PollRepository(NHibernateHelper.GetCurrentSession());
     this.pollID = pollID;
     this.name = name;
     this.poll = pollRepository.GetPollByID(pollID);
     this.field = field;
     this.include = include;
     this.tick = tick;
     this.questions = questions;
     this.responses = responses;
     this.poll = pollRepository.GetPollByID(pollID);
     this.selectedEntities = new List<Entity>();
 }
 public DetailsViewModel(int participantID, int pollID)
 {
     var pollRepository = new PollRepository(NHibernateHelper.GetCurrentSession());
     var participantRepository = new ParticipantRepository(NHibernateHelper.GetCurrentSession());
     this.poll = pollRepository.GetPollByID(pollID);
     Dictionary<Participant, Dictionary<String, String>> groupies = new Dictionary<Participant, Dictionary<String, String>>();
     if (poll.isGroup)
     {
         foreach (Participant participant in participantRepository.GetParticipantsOfGroup(participantRepository.GetGroupByGroupID(participantID), poll))
             groupies.Add(participant,participantRepository.GetParticipantDetailsByParticipantID(participant.participantID,pollID));
         participants = groupies;
         this.group = participantRepository.GetGroupByGroupID(participantID);
     }
     else this.fieldValues = participantRepository.GetParticipantDetailsByParticipantID(participantID,pollID);
 }
 public ApplicationController(ISession session)
 {
     this.session = session;
     this.transaction = session.BeginTransaction();
     this.clientCodeRepository = new ClientCodeRepository(session);
     this.entityRepository = new EntityRepository(session);
     this.fieldsTemplateRepository = new FieldsTemplateRepository(session);
     this.messageRepository = new MessageRepository(session);
     this.participantRepository = new ParticipantRepository(session);
     this.pollRepository = new PollRepository(session);
     this.questionRepository = new QuestionRepository(session);
     this.reportRepository = new ReportRepository(session);
     this.responseRepository = new ResponseRepository(session);
     this.roleRepository = new RoleRepository(session);
     this.templateRepository = new TemplateRepository(session);
     this.userRepository = new UserRepository(session);
 }
 public void DeleteGroup(int groupID, int pollID)
 {
     var pollRepository = new PollRepository(session);
     ParticipantGroup group = GetGroupByGroupID(groupID);
     foreach (Participant participant in pollRepository.GetPollByID(pollID).participants)
         if (participant.group == group) participant.group = null;
     session.Delete(group);
 }
 public ICollection<Dictionary<String, String>> GetParticipantValuesByPollID(int pollID)
 {
     var poll = new PollRepository(session).GetPollByID(pollID);
     IList<Participant> participants = (from p in poll.participants orderby p.participantID select p).ToList<Participant>();
     ICollection<Dictionary<String, String>> values = new HashSet<Dictionary<String, String>>();
     foreach (var participant in participants)
     {
         values.Add(GetParticipantDetailsByParticipantID(participant.participantID, pollID));
     }
     return values;
 }
 public Dictionary<String, String> GetParticipantDetailsByParticipantID(int participantID, int pollID)
 {
     var participant = GetParticipantByParticipantID(participantID);
     var poll = new PollRepository(session).GetPollByID(pollID);
     Dictionary<String, String> partici = new Dictionary<String, String>();
     partici.Add("Participant ID", participant.participantID.ToString());
     partici.Add("Device ID", participant.deviceID.ToString());
     partici.Add("First Name", participant.firstName);
     partici.Add("Last Name", participant.lastName);
     foreach (var field in poll.participantFields)
     {
         var q = (from p in field.fieldValues where (p.participant != null && p.participant.Equals(participant)) select p).ToList<ParticipantFieldValue>();
         if (q.Count() == 0) partici.Add(field.name, "");
         else partici.Add(field.name, q.ElementAt(0).value);
     }
     if (participant.entity != null) partici.Add("Entity", participant.entity.name);
     else partici.Add("Entity", "");
     return partici;
 }
 public ICollection<Dictionary<String, String>> GetGroupValuesByPollID(int pollID)
 {
     var poll = new PollRepository(session).GetPollByID(pollID);
     IList<ParticipantGroup> groups = poll.groups;
     ICollection<Dictionary<String, String>> values = new HashSet<Dictionary<String, String>>();
     foreach (var group in groups)
     {
         values.Add(GetGroupDetailsByGroup(group, pollID));
     }
     return values;
 }
 public Dictionary<String, String> GetGroupDetailsByGroup(ParticipantGroup groups, int pollID)
 {
     var poll = new PollRepository(session).GetPollByID(pollID);
     Dictionary<String, String> groupd = new Dictionary<String, String>();
     groupd.Add("groupID", groups.groupID.ToString());
     groupd.Add("Name", groups.name);
     foreach (var field in poll.participantFields)
     {
         var q = (from p in field.fieldValues where (p.groupd != null && p.groupd.Equals(groups)) select p).ToList<ParticipantFieldValue>();
         if (q.Count() == 0) groupd.Add(field.name, "");
         else groupd.Add(field.name, q.ElementAt(0).value);
     }
     if (groups.entity != null) groupd.Add("Entity", groups.entity.name);
     else groupd.Add("Entity", "");
     return groupd;
 }
        public int[] GetQuestionResults(int questionID)
        {
            var pollRepository = new PollRepository(session);
            var questionRepository = new QuestionRepository(session);
            var question = questionRepository.GetQuestionByID<Question>(questionID);
            IDictionary<String, int> responses = new Dictionary<String, int>();
            IList<String> correctOptions = new List<String>();
            int[] responseStatistics = new int[2];
            var poll = pollRepository.GetPollContainingQuestion(question);

            if (question.type == QuestionType.Numeric)
            {
                // If the question is numeric
                var numericQuestion = questionRepository.GetQuestionByID<NumericQuestion>(questionID);

                int numCorrect = 0;
                int numIncorrect = 0;

                foreach (var response in numericQuestion.responses)
                {

                    // Check if the answer is correct
                    if ((Convert.ToInt32(response.response) < numericQuestion.lessThan) &&
                        (Convert.ToInt32(response.response) > numericQuestion.greaterThan))
                    {
                        numCorrect++;
                    }
                    else
                    {
                        numIncorrect++;
                    }
                }

                responses.Add("Correct [" + numericQuestion.greaterThan.ToString() +
                            " - " + numericQuestion.lessThan.ToString() + "]", numCorrect);
                responses.Add("Incorrect", numIncorrect);
                responseStatistics[0] = numCorrect + numIncorrect;
                responseStatistics[1] = numCorrect;
            }
            else if (question.type == QuestionType.Alphanumeric)
            {
                // If the question is alphanumeric
                var alphaQuestion = questionRepository.GetQuestionByID<AlphanumericQuestion>(questionID);

                //  Get correct responses
                int numCorrect = 0;
                int numIncorrect = 0;
                int total = 0;

                foreach (var response in alphaQuestion.responses)
                {

                    foreach (var answer in alphaQuestion.answers)
                    {
                        if (response.response.Equals(answer.answer))
                        {
                            numCorrect++;
                        }
                    }
                    total++;
                }

                // Build a string of correct answers
                String correctAnswers = "";
                foreach (var answer in alphaQuestion.answers)
                {
                    if (correctAnswers != "")
                    {
                        correctAnswers += ", ";
                    }
                    correctAnswers += answer.answer;
                }

                responses.Add("Correct [" + correctAnswers + "]", numCorrect);
                numIncorrect = total - numCorrect;
                responses.Add("Incorrect", numIncorrect);
                responseStatistics[0] = total;
                responseStatistics[1] = numCorrect;
            }
            else
            {
                var multipleQuestion = questionRepository.GetQuestionByID<MultipleChoiceQuestion>(questionID);
                int numCorrect = 0;
                int total = 0;

                foreach (var option in multipleQuestion.options)
                {
                    total += option.responses.Count;
                    if (option.correctCurrent)
                    {
                        numCorrect += option.responses.Count;
                    }
                }
                total = total / multipleQuestion.allowedAnswers;
                numCorrect = numCorrect / multipleQuestion.allowedAnswers;
                responseStatistics[0] = total;
                responseStatistics[1] = numCorrect;
            }
            return responseStatistics;
        }
 public NewParticipantViewModel(Boolean success,int pollID)
 {
     var pollRepository = new PollRepository(NHibernateHelper.GetCurrentSession());
     this.success = success;
     this.poll = pollRepository.GetPollByID(pollID);
 }