// GET api/contributors/5 public SofETest.Models.Contributor Get(int id) { SofETest.Models.Contributor contributor = null; contributor = Services.Contributors.Get(id); return(contributor); }
// DELETE api/contributors/5 public HttpResponseMessage Delete(int id) { HttpResponseMessage response = null; try { SofETest.Models.Contributor contributor = Services.Contributors.Get(id); Services.Contributors.Delete(contributor); response = Request.CreateResponse(HttpStatusCode.OK); } catch (Exception ex) { string msg = ex.Message.Replace("\r\n", "\r\n "); response = new HttpResponseMessage(HttpStatusCode.Conflict); response.Headers.Add("Error-Description", msg); } return(response); }
public HttpResponseMessage Post(Contributor contributor) { HttpResponseMessage response = null; try { Mapper.CreateMap <Contributor, SofETest.Models.Contributor>(); SofETest.Models.Contributor c = Mapper.Map <Contributor, SofETest.Models.Contributor>(contributor); Services.Contributors.Create(c); response = Request.CreateResponse(HttpStatusCode.Created, contributor); string uri = Url.Route(null, new { id = c.Id }); response.Headers.Location = new Uri(Request.RequestUri, uri); } catch (Exception ex) { string msg = ex.Message.Replace("\r\n", "\r\n "); response = new HttpResponseMessage(HttpStatusCode.Conflict); response.Headers.Add("Error-Description", msg); } return(response); }