示例#1
0
        public Question CreateQuestionInBank(int questionID, string description)
        {
            using (var db = new EvalContext())
            {
                // tjek for eksisterende question. Hvis der er en så returner null, da redigering ikke skal ske gennem Create (rest)
                var existingQuestion = db.Question.Find(questionID);

                if (existingQuestion != null)
                {
                    return(null);
                }

                var question = new Question
                {
                    question_id      = questionID,
                    questionnaire_id = 1337,
                    description      = description
                };

                db.Question.Add(question);

                db.SaveChanges();

                return(question);
            }
        }
示例#2
0
        public bool DeleteQuestion(int questionID)
        {
            using (var db = new EvalContext())
            {
                var existingQuestion = db.Question.Find(questionID);

                if (existingQuestion != null)
                {
                    db.Question.Remove(existingQuestion);
                    db.SaveChanges();
                    return(true);
                }
            }
            // statuscode kræver false hvis der ikke kunne findes noget at slette og true, hvis der var noget at slette som slettes.
            return(false);
        }
示例#3
0
        public Evaluation AddReport(int evaluationID, string report)
        {
            using (var db = new EvalContext())
            {
                //var existingEvaluation = db.Evaluation.AsNoTracking().Where(e => e.evaluation_id == evaluationID).First();
                var existingEvaluation = db.Evaluation.Find(evaluationID);
                existingEvaluation.report = report;

                db.Evaluation.Attach(existingEvaluation);
                var entry = db.Entry(existingEvaluation);
                entry.Property(x => x.report).IsModified = true;

                db.SaveChanges();


                return(existingEvaluation);
            }
        }
示例#4
0
        public void  CreateAnswer(int question_id, int questionnaire_id, int answer)
        {
            using (var db = new EvalContext())
            {
                var studyanswer = new Answer
                {
                    question_id      = question_id,
                    questionnaire_id = questionnaire_id,
                    answer           = answer
                };

                db.Answer.Add(studyanswer);

                db.SaveChanges();

                // returner den nyoprettede answer
                //return GetAnswers();
            }
        }