public HttpResponseMessage Post(BugDTO dto, string comments=null) { Bug bug; if(dto.Id != 0) { bug = _bugsRepository.Get(dto.Id); if (bug == null) return new HttpResponseMessage(HttpStatusCode.NotFound); bug.Approve(); return Request.CreateResponse(HttpStatusCode.OK, GetBacklogBugDtos()); } bug = Mapper.Map<BugDTO, Bug>(dto); bug.Approve(); _bugsRepository.Add(bug); var response = Request.CreateResponse(HttpStatusCode.Created, GetBacklogBugDtos()); //i still don't like this because it's fragmenting management of my links response.Headers.Location = new Uri(HostUriFromRequest(Request), bug.Id.ToString(CultureInfo.InvariantCulture)); return response; }
public HttpResponseMessage<IEnumerable<BugDTO>> Post(BugDTO dto, string comments) { Bug bug; if(dto.Id != 0) { bug = _bugsRepository.Get(dto.Id); if(bug == null) throw new HttpResponseException(HttpStatusCode.NotFound); bug.Approve(); return new HttpResponseMessage<IEnumerable<BugDTO>>(GetBacklogBugDtos()); } bug = Mapper.Map<BugDTO, Bug>(dto); bug.Approve(); _bugsRepository.Add(bug); var response = new HttpResponseMessage<IEnumerable<BugDTO>>(GetBacklogBugDtos(), HttpStatusCode.Created); //i still don't like this because it's fragmenting management of my links response.Headers.Location = new Uri(HostUriFromRequest(Request), bug.Id.ToString()); return response; }