Beispiel #1
0
        // legger til innkommdnde spøsmål i databasen
        public bool saveQuestion(Question inQuestion)
        {
            if (inQuestion != null)
            {
                var newQuestion = new Question
                {
                    title = inQuestion.title,
                    question = inQuestion.question,
                    email = inQuestion.email,
                    name = inQuestion.name
                };
                using (var db = new FaqContext())
                {
                    try
                    {
                        db.Questions.Add(newQuestion);
                        db.SaveChanges();
                        return true;

                    }
                    catch (Exception ex)
                    {
                        return false;
                    }
                }

            }
            return false;
        }
        public HttpResponseMessage Post( Question inQuestion)
        {
            if (ModelState.IsValid)
            {
                if(faqDb.saveQuestion(inQuestion))
                {
                    return new HttpResponseMessage()
                    {
                        StatusCode = HttpStatusCode.OK
                    };

                }
            }
            return new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.NotFound,
                Content = new StringContent("FEIL: Klarte ikke lagre spørsmål..")
            };
        }