// PUT: api/Questions/5
        public IHttpActionResult Put(int id, [FromBody] QuestionFullDTO value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != value.QuestionId)
            {
                return(BadRequest());
            }

            try
            {
                this._questionService.UpdateQuestion(value);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (this._questionService.GetQuestionById(id) != null)
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        // GET: api/Questions/5
        public IHttpActionResult Get(int id)
        {
            QuestionFullDTO questionDTO = this._questionService.GetQuestionById(id);

            if (questionDTO == null)
            {
                return(NotFound());
            }

            return(Ok(questionDTO));
        }
Exemple #3
0
        public Question RecreateFullDTO(QuestionFullDTO questionDTO)
        {
            var c = new Question()
            {
                Answers      = questionDTO.Answers.Select(x => _answerFactory.RecreateFullDTO(x)).ToList(),
                CreationDate = questionDTO.CreationDate,
                Deleted      = questionDTO.Deleted,
                Description  = questionDTO.Description,
                Public       = questionDTO.Public,
                QuestionId   = questionDTO.QuestionId,
                Title        = questionDTO.Title,
                UpdateDate   = questionDTO.UpdateDate
            };

            return(c);
        }
Exemple #4
0
        public QuestionFullDTO CreateFullDTO(Question question)
        {
            var ret = new QuestionFullDTO()
            {
                QuestionId   = question.QuestionId,
                Title        = question.Title,
                CreationDate = question.CreationDate,
                Deleted      = question.Deleted,
                Description  = question.Description,
                Answers      = question.Answers.Select(x => _answerFactory.CreateFullDTO(x)).ToList(),
                Public       = question.Public,
                UpdateDate   = question.UpdateDate
            };

            return(ret);
        }
        // POST: api/Questions
        public IHttpActionResult Post([FromBody] QuestionFullDTO value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                this._questionService.AddQuestion(value);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(CreatedAtRoute("DefaultApi", new { id = value.QuestionId }, value));
        }
 public void DeleteQuestion(QuestionFullDTO questionDTO)
 {
     this._questionRepository.Delete(this._questionFactory.RecreateFullDTO(questionDTO));
     this._questionRepository.SaveChanges();
 }
 public void UpdateQuestion(QuestionFullDTO value)
 {
     this._questionRepository.Update(this._questionFactory.RecreateFullDTO(value));
     this._questionRepository.SaveChanges();
 }