예제 #1
0
        public HttpResponseMessage Post(AssetValue val)
        {
            if (val == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

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

            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(val.Id, ODataVersion.V3))));

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

            return(response);
        }
예제 #2
0
        public void Create(object o)
        {
            var assets = o as AssetValue;

            assets.GovernorId = assets.Governor.Id;
            _rep.Create(assets);
        }