Ejemplo n.º 1
0
 public HttpResponseMessage Edit([FromBody] Question questionToEdit, [FromUri] Guid Id)
 {
     try
     {
         if (questionLogic.Find(Id).Author.Id != CurrentUserId())
         {
             throw new Unauthorised();
         }
         questionToEdit.Id = Id;
         QuestionDTO questionEdit = QuestionMapper.ToDTO(questionToEdit);
         questionEdit.Tags = SetTags(questionToEdit.Tags);
         QuestionDTO question = questionLogic.Edit(questionEdit);
         if (question == null)
         {
             throw new NoSuchQuestionFound();
         }
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, new { question });
         return(response);
     }
     catch (Unauthorised e)
     {
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Forbidden, new { error = e.Message });
         return(response);
     }
     catch (NoSuchQuestionFound e)
     {
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, new { error = e.Message });
         return(response);
     }
     catch (Exception e)
     {
         HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.BadRequest, e.Message);
         return(response);
     }
 }