public HttpResponseMessage PostQuestion(Question question) { if (ModelState.IsValid) { try { question.Initialize(); var createdQuestion = Uow.Questions.Add(question); Uow.Commit(); EmailManager.SendEmails(question); var response = Request.CreateResponse(HttpStatusCode.Created, question); var referrerUrl = Request.Headers.Referrer.AbsoluteUri; response.Headers.Location = new Uri(referrerUrl.Substring(0, referrerUrl.LastIndexOf('/')) + "/question/detail/" + createdQuestion.QuestionId); return response; } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.InternalServerError); } } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }
public HttpResponseMessage PutQuestion(string id, Question question) { if (ModelState.IsValid && id == question.QuestionId) { Uow.Questions.Update(question.Id, question); Uow.Commit(); var response = Request.CreateResponse(HttpStatusCode.Created, question); response.Headers.Location = new Uri(Request.Headers.Referrer.AbsoluteUri); return response; } else { return Request.CreateResponse(HttpStatusCode.BadRequest); } }