Beispiel #1
0
        public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
        {
            ContentIdRecord contentIdRecord = ContentIdHelper.GetReferencedContentIdEntity(actionContext.Request);

            if (contentIdRecord == null)
            {
                // Value doesn't exist
                return(false);
            }

            if (bindingContext.ModelType.IsAssignableFrom(contentIdRecord.EntityType))
            {
                bindingContext.Model = contentIdRecord.Entity;
                return(true);
            }
            else
            {
                string errorMessage = string.Format("Content-ID reference ${0} contains an entity of type {1}, which could not be converted to type {2}.",
                                                    contentIdRecord.ContentId,
                                                    contentIdRecord.EntityType,
                                                    bindingContext.ModelType);
                bindingContext.ModelState.AddModelError(bindingContext.ModelName, errorMessage);
                return(false);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sends a single OData changeset request.
        /// </summary>
        /// <param name="invoker">The invoker.</param>
        /// <param name="request">The request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns></returns>
        private async Task <HttpResponseMessage> SendSubRequestAsync(HttpMessageInvoker invoker, HttpRequestMessage request, CancellationToken cancellationToken)
        {
            // Modifies the request Uri if there's a Content-ID reference (eg http://localhost/odata/$46/Messages )
            ContentIdHelper.ResolveContentIdReferenceInRequestUrl(request);

            HttpResponseMessage response = await invoker.SendAsync(request, cancellationToken);

            ChangeSetExtensions.CopyContentIdHeaderToResponse(request, response);

            ChangeSetExtensions.StoreLocationHeaderForContentId(response, _changeSetContext);

            return(response);
        }
Beispiel #3
0
        public static bool ContentIdReferenceToEntity(this HttpRequestMessage request, string reference, out object referencedEntity)
        {
            referencedEntity = null;
            int contentId;

            if (!ContentIdHelper.TryParseContentIdReference(reference, out contentId))
            {
                return(false);
            }

            ChangeSetContext changeSetContext = request.GetChangeSetContext();

            if (changeSetContext != null)
            {
                ContentIdRecord contentIdRecord = changeSetContext.GetContentIdRecord(contentId);
                if (contentIdRecord != null)
                {
                    referencedEntity = contentIdRecord.Entity;
                }
            }

            return(referencedEntity != null);
        }