Exemplo n.º 1
0
        public IQueryable <ModelStudentAnswer> GetStudentAnswersByTest(int testid)
        {
            //TODO: needs testing
            var           model                  = new ModelStudentAnswer();
            StoreQuestion questionStore          = new StoreQuestion(_ctx);
            IQueryable <ModelQuestion> questions = questionStore.GetQuestionsByTest(testid);
            List <ModelStudentAnswer>  final     = new List <ModelStudentAnswer>();

            model.Get(_ctx).ToList().ForEach(cur =>
            {
                ModelQuestion qq = questionStore.GetQuestion(cur.QuestionID);
                foreach (ModelQuestion curQQ in questions)
                {
                    if (curQQ.QuestionID == cur.QuestionID)
                    {
                        final.Add(cur);
                    }
                }
            });
            return(final.AsQueryable());
        }
Exemplo n.º 2
0
        public IQueryable <ModelStudentAnswer> GetStudentAnswersByStudentByTest(string username, int testid)
        {
            var                       model         = new ModelStudentAnswer();
            StoreQuestion             questionStore = new StoreQuestion(_ctx);
            List <ModelQuestion>      questions     = questionStore.GetQuestionsByTest(testid).ToList();
            List <ModelStudentAnswer> modelQuestion = model.Get(_ctx).Where(x => x.Username == username).ToList();
            List <ModelStudentAnswer> final         = new List <ModelStudentAnswer>();

            modelQuestion.ForEach(cur =>
            {
                ModelQuestion qq = questionStore.GetQuestion(cur.QuestionID);
                foreach (ModelQuestion curQQ in questions)
                {
                    if (curQQ.QuestionID == cur.QuestionID)
                    {
                        final.Add(cur);
                    }
                }
            });
            return(final.AsQueryable());
        }
Exemplo n.º 3
0
        public void CreateStudentAnswer(ModelStudentAnswer model)
        {
            using (var transaction = _ctx.Database.BeginTransaction())
            {
                try
                {
                    model.StudentAnswerActive = true;

                    var entity = model.ToEntity();

                    _ctx.Insert(entity);
                    _ctx.SaveChanges();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new ArgumentException(e.Message);
                }
            }
        }
Exemplo n.º 4
0
        public void UpdateStudentAnswer(ModelStudentAnswer model)
        {
            using (var transaction = _ctx.Database.BeginTransaction())
            {
                try
                {
                    var entity = _ctx.StudentAnswers.FirstOrDefault(x => x.SAID == model.SAID);

                    model.Update(entity);

                    _ctx.Update(entity);
                    _ctx.SaveChanges();

                    transaction.Commit();
                }
                catch (Exception e)
                {
                    transaction.Rollback();
                    throw new ArgumentException(e.Message);
                }
            }
        }
Exemplo n.º 5
0
        public IQueryable <ModelStudentAnswer> GetStudentAnswersByQuestion(int qid)
        {
            var model = new ModelStudentAnswer();

            return(model.Get(_ctx).Where(x => x.QuestionID == qid));
        }
Exemplo n.º 6
0
        public IQueryable <ModelStudentAnswer> GetStudentAnswersByStudent(string username)
        {
            var model = new ModelStudentAnswer();

            return(model.Get(_ctx).Where(x => x.Username == username));
        }
Exemplo n.º 7
0
        public ModelStudentAnswer GetStudentAnswer(int said)
        {
            var model = new ModelStudentAnswer();

            return(model.Get(_ctx).FirstOrDefault(x => x.SAID == said));
        }
Exemplo n.º 8
0
        public IQueryable <ModelStudentAnswer> ReadStudentAnswers()
        {
            var model = new ModelStudentAnswer();

            return(model.Get(_ctx));
        }