コード例 #1
0
        /// <inheritdoc />
        public void Declare(string localId, string resourceType)
        {
            ArgumentGuard.NotNull(localId, nameof(localId));
            ArgumentGuard.NotNull(resourceType, nameof(resourceType));

            AssertIsNotDeclared(localId);

            _idsTracked[localId] = new LocalIdState(resourceType);
        }
コード例 #2
0
        /// <inheritdoc />
        public void Declare(string localId, string resourceType)
        {
            if (localId == null)
            {
                throw new ArgumentNullException(nameof(localId));
            }
            if (resourceType == null)
            {
                throw new ArgumentNullException(nameof(resourceType));
            }

            AssertIsNotDeclared(localId);

            _idsTracked[localId] = new LocalIdState(resourceType);
        }
コード例 #3
0
        /// <inheritdoc />
        public void Assign(string localId, string resourceType, string stringId)
        {
            ArgumentGuard.NotNullNorEmpty(localId, nameof(localId));
            ArgumentGuard.NotNullNorEmpty(resourceType, nameof(resourceType));
            ArgumentGuard.NotNullNorEmpty(stringId, nameof(stringId));

            AssertIsDeclared(localId);

            LocalIdState item = _idsTracked[localId];

            AssertSameResourceType(resourceType, item.ResourceType, localId);

            if (item.ServerId != null)
            {
                throw new InvalidOperationException($"Cannot reassign to existing local ID '{localId}'.");
            }

            item.ServerId = stringId;
        }
コード例 #4
0
        /// <inheritdoc />
        public string GetValue(string localId, string resourceType)
        {
            ArgumentGuard.NotNullNorEmpty(localId, nameof(localId));
            ArgumentGuard.NotNullNorEmpty(resourceType, nameof(resourceType));

            AssertIsDeclared(localId);

            LocalIdState item = _idsTracked[localId];

            AssertSameResourceType(resourceType, item.ResourceType, localId);

            if (item.ServerId == null)
            {
                throw new JsonApiException(new Error(HttpStatusCode.BadRequest)
                {
                    Title  = "Local ID cannot be both defined and used within the same operation.",
                    Detail = $"Local ID '{localId}' cannot be both defined and used within the same operation."
                });
            }

            return(item.ServerId);
        }