Exemplo n.º 1
0
        public HttpResponseMessage Post(Governor gov)
        {
            if (gov == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            _rep.Create(gov);
            var response = Request.CreateResponse(HttpStatusCode.Created, gov);

            var odataPath = Request.GetODataPath();

            if (odataPath == null)
            {
                throw new InvalidOperationException("There is no ODataPath in the request.");
            }
            var entitySetPathSegment = odataPath.Segments.FirstOrDefault() as EntitySetPathSegment;

            if (entitySetPathSegment == null)
            {
                throw new InvalidOperationException("ODataPath doesn't start with EntitySetPathSegment.");
            }

            response.Headers.Location = new Uri(Url.ODataLink(entitySetPathSegment, new KeyValuePathSegment(ODataUriUtils.ConvertToUriLiteral(gov.Id, ODataVersion.V3))));

            //response.Headers.Location = new Uri(Url.ODataLink(new EntitySetPathSegment("Governors"), new KeyValuePathSegment(gov.Id.ToString())));

            return(response);
        }
Exemplo n.º 2
0
 public void Create(object o)
 {
     _rep.Create(o as Governor);
 }