public Poll Put([FromBody] Poll input) { IPoll poll = null; try { var userID = MyVoteAuthentication.GetCurrentUserID(); poll = this.PollFactory.Value.Create(userID.Value); var newPoll = this.SavePoll(input, poll); return(PollController.MapPollToModel(newPoll)); } catch (ValidationException ex) { var brokenRules = poll.GetBrokenRules().ToString(); throw new HttpResponseException( new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = ex.Message.Replace(Environment.NewLine, " "), Content = new StringContent(brokenRules), RequestMessage = Request }); } catch (Exception ex) { throw new HttpResponseException( new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = ex.Message.Replace(Environment.NewLine, " "), Content = new StringContent(ex.ToString()), RequestMessage = Request }); } }
public Poll Put(int id, [FromBody] Poll input) { IPoll poll = null; try { poll = this.PollFactory.Value.Fetch(id); var updatedPoll = this.SavePoll(input, poll); return(PollController.MapPollToModel(updatedPoll)); } catch (ValidationException ex) { var brokenRules = poll.GetBrokenRules().ToString(); throw new HttpResponseException( new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = ex.Message.Replace(Environment.NewLine, " "), Content = new StringContent(brokenRules), RequestMessage = Request }); } catch (NullReferenceException ex) { throw new HttpResponseException( new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound, ReasonPhrase = string.Format("No resource matching {0} found", id), Content = new StringContent(ex.ToString()), RequestMessage = Request }); } catch (Exception ex) { throw new HttpResponseException( new HttpResponseMessage { StatusCode = HttpStatusCode.BadRequest, ReasonPhrase = ex.Message.Replace(Environment.NewLine, " "), Content = new StringContent(ex.ToString()), RequestMessage = Request }); } }