Beispiel #1
0
        public bool ValidatePassword(string password_hash)
        {
            var context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);
            var User    = context.User.Where(p => p.Id == id).FirstOrDefault();

            return(String.Equals(User.password_hash, password_hash));
        }
Beispiel #2
0
        public API_User ActionRegister(Frontend_User f_User)
        {
            var      context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);
            API_User A       = new API_User();

            A.email = f_User.email;
            if (context.User.Where(p => p.email == f_User.email).Any())
            {
                throw new Exception();
            }
            else
            {
                A.name = f_User.email;
                A.GenerateAccesToken();
                var k = new User
                {
                    name          = A.name,
                    email         = f_User.email,
                    password_hash = f_User.password_hash
                };
                context.User.InsertOnSubmit(k);
                context.User.Context.SubmitChanges();
                return(A);
            }
        }
        public Question_Stats GetQuestionStart(int _question_id)
        {
            var           context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);
            poll_question A       = new poll_question();

            A.id   = _question_id;
            A.text = Convert.ToString(context.pool_question.Where(p => p.question_id == _question_id).Select(p => p.text).FirstOrDefault());
            Question_Stats Res = new Question_Stats(A);

            return(Res);
        }
Beispiel #4
0
        public Poll GetPoolForID(int _question_id)
        {
            poll_question a   = new poll_question();
            Poll          Res = new Poll();

            Res.id = _question_id;
            var context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);

            Res.quesstion = Convert.ToString(context.pool_question.Where(p => p.question_id == _question_id).Select(p => p.text).First());
            Res.answers   = a.GetAnswers(_question_id);
            return(Res);
        }
        public void PostUserSubmission(API_User _user, int _question_id, int _answer_id)
        {
            var context    = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);
            int answers_id = Convert.ToInt32(context.answers_to_questions.Where(p => p.answer_id == _answer_id).Where(p => p.question_id == _question_id).Select(p => p.Id).FirstOrDefault());
            var k          = new user_submission
            {
                user_id   = _user.id,
                answer_id = answers_id
            };

            context.user_submission.InsertOnSubmit(k);
            context.user_submission.Context.SubmitChanges();
        }
Beispiel #6
0
        public int[] GetAnswersLinks(int question_id)
        {
            var context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);
            int n       = Convert.ToInt32(context.answers_to_questions.Where(p => p.question_id == question_id).Count());

            int[] a = new int[n];

            for (int i = 0; i < n; i++)
            {
                a[i] = Convert.ToInt32(context.answers_to_questions.Where(p => p.question_id == question_id).Select(p => p.answer_id).Skip(i).Take(1).Skip(n - i - 1));
            }
            return(a);
        }
Beispiel #7
0
        public poll_answer[] GetAnswers(int question_id)
        {
            var context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);

            int[]         a = GetAnswersLinks(question_id);
            poll_answer[] A = new poll_answer[a.Length];
            for (int i = 0; i < a.Length; i++)
            {
                A[i].id   = Convert.ToInt32(context.pool_answer.Where(p => p.answer_id == a[i]).Select(p => p.answer_id).Skip(i).Take(1).Skip(a.Length - i));
                A[i].text = Convert.ToString(context.pool_answer.Where(p => p.answer_id == a[i]).Select(p => p.text).Skip(i).Take(1).Skip(a.Length - i));
            }
            return(A);
        }
Beispiel #8
0
        public Poll[] ToPoll(int[] question_ids)
        {
            var context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);

            Poll[] A = new Poll[question_ids.Length];
            for (int i = 0; i < question_ids.Length; i++)
            {
                A[i].id        = Convert.ToInt32(context.pool_question.Where(p => p.question_id == question_ids[i]).Select(p => p.question_id).Skip(i).Take(1).Skip(question_ids.Length - i));
                A[i].quesstion = Convert.ToString(context.pool_question.Where(p => p.question_id == question_ids[i]).Select(p => p.text).Skip(i).Take(1).Skip(question_ids.Length - i));
                A[i].answers   = GetAnswers(question_ids[i]);
            }
            return(A);
        }
Beispiel #9
0
        // GET: PoolQuestion
        public Poll[]  GetPool()
        {
            poll_question a       = new poll_question();
            var           context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);
            int           n       = context.pool_question.Count();

            int[] mass = new int[n];
            for (int i = 0; i < n; i++)
            {
                mass[i] = Convert.ToInt32(context.pool_question.Select(p => p.question_id).Skip(i).Take(1).Skip(n - i));
            }
            return(a.ToPoll(mass));
        }
Beispiel #10
0
        public void save(Submission sub)
        {
            var context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);

            if (sub.user_id.ToString() == null)
            {
                throw new Exception();
            }
            else
            if (!sub.answers.Any())
            {
                throw new Exception();
            }
            else
            if (!context.user_submission.Where(p => p.user_id == user_id).Any())
            {
                throw new Exception();
            }
        }
Beispiel #11
0
        public Question_Stats(poll_question _question)
        {
            var context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);

            question      = _question;
            answers_total = Convert.ToInt32(context.answer_total(question.id));
            poll_answer[] A = _question.GetAnswers(_question.id);
            int[]         B = new int[A.Length];
            for (int i = 0; i < A.Length; i++)
            {
                B[i] = Convert.ToInt32(context.votes_total(A[i].id));
            }
            VtoA[] Res = new VtoA[A.Length];
            for (int i = 0; i < A.Length; i++)
            {
                Res[i].answer      = A[i];
                Res[i].votes_total = B[i];
            }
            answers_stats = Res;
        }
Beispiel #12
0
        public QtoA[] CollectStats(int user_id)
        {
            var context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);
            int n       = Convert.ToInt32(context.user_submission.Where(p => p.user_id == user_id).Count());

            QtoA[] Res  = new QtoA[n];
            int[]  mass = new int[n];
            for (int i = 0; i < n; i++)
            {
                mass[i] = Convert.ToInt32(context.user_submission.Where(p => p.user_id == user_id).Select(p => p.answer_id).Skip(i).Take(1).Skip(n - i));
            }
            for (int i = 0; i < n; i++)
            {
                int answer_id   = Convert.ToInt32(context.answers_to_questions.Where(p => p.Id == mass[i]).Select(p => p.answer_id).Skip(i).Take(1).Skip(n - i));
                int question_id = Convert.ToInt32(context.answers_to_questions.Where(p => p.Id == mass[i]).Select(p => p.question_id).Skip(i).Take(1).Skip(n - i));
                Res[i].answer.id     = answer_id;
                Res[i].answer.text   = Convert.ToString(context.pool_answer.Where(p => p.answer_id == answer_id).Select(p => p.text));
                Res[i].question.id   = question_id;
                Res[i].question.text = Convert.ToString(context.pool_question.Where(p => p.question_id == question_id).Select(p => p.text));
            }
            return(Res);
        }
Beispiel #13
0
        public Submission fetch(int user_id)
        {
            var        context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);
            Submission Res     = new Submission(user_id);

            if (context.user_submission.Where(p => p.user_id == user_id).Any())
            {
                int   n    = Convert.ToInt32(context.user_submission.Where(p => p.user_id == user_id).Count());
                int[] mass = new int[n];
                for (int i = 0; i < n; i++)
                {
                    mass[i] = Convert.ToInt32(context.user_submission.Where(p => p.user_id == user_id).Select(p => p.answer_id).Skip(i).Take(1).Skip(n - i));
                    Res.answers[i].answer_id   = Convert.ToInt32(context.answers_to_questions.Where(p => p.Id == mass[i]).Select(p => p.answer_id).Skip(i).Take(1).Skip(n - i));
                    Res.answers[i].question_id = Convert.ToInt32(context.answers_to_questions.Where(p => p.Id == mass[i]).Select(p => p.question_id).Skip(i).Take(1).Skip(n - i));
                }
                return(Res);
            }
            else
            {
                throw new Exception();
            }
        }
Beispiel #14
0
        public API_User ActionLogin(Frontend_User f_User)
        {
            var      context       = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);
            API_User A             = new API_User();
            string   email         = f_User.email;
            string   password_hash = f_User.password_hash;

            if (context.User.Where(p => p.email == email).Any())
            {
                var _user = context.User.Where(p => p.email == email).FirstOrDefault();
                A.id   = _user.Id;
                A.name = _user.name;
            }
            if (!A.ValidatePassword(f_User.password_hash))
            {
                throw new Exception();
            }
            else
            {
                A.GenerateAccesToken();
            }
            return(A);
        }
Beispiel #15
0
        public int GetNumSubmission(int id)
        {
            var context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);

            return(context.user_submission.Where(p => p.user_id == id).Count());
        }
Beispiel #16
0
        public int GetVotesCount(int answer_id)
        {
            var context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);

            return(Convert.ToInt32(context.votes_total(answer_id)));
        }
Beispiel #17
0
        public int GetAnswerRelation(int answer_id)
        {
            var context = new API_DBDataContext(ConfigurationManager.ConnectionStrings["Connections string"].ConnectionString);

            return(context.answers_to_questions.Where(p => p.answer_id == answer_id).Count());
        }