예제 #1
0
        protected override async Task <TEntity> UpdateEntityAsync(string id, IDictionary <string, object> attrs,
                                                                  IDictionary <string, string> relationships)
        {
            try
            {
                return(await Entities.UpdateAsync(e => e.Id == id, update =>
                {
                    foreach (KeyValuePair <string, object> attr in attrs)
                    {
                        UpdateAttribute(update, attr.Key, attr.Value);
                    }

                    foreach (KeyValuePair <string, string> rel in relationships)
                    {
                        IRelationship <TEntity> relationship = GetRelationship(rel.Key);
                        if (!relationship.Update(update, new[] { rel.Value }))
                        {
                            string relName = JsonApiContext.ResourceGraph.GetPublicRelationshipName <TResource>(rel.Key);
                            throw new JsonApiException(StatusCodes.Status400BadRequest,
                                                       $"The relationship '{relName}' cannot be updated.");
                        }
                    }
                }));
            }
            catch (DuplicateKeyException)
            {
                throw new JsonApiException(StatusCodes.Status409Conflict,
                                           "Another entity with the same key already exists.");
            }
        }
예제 #2
0
        protected override Task <TEntity> UpdateEntityRelationshipAsync(string id, string propertyName,
                                                                        IEnumerable <string> relationshipIds)
        {
            IRelationship <TEntity> relationship = GetRelationship(propertyName);

            return(Entities.UpdateAsync(e => e.Id == id, update =>
            {
                if (!relationship.Update(update, relationshipIds))
                {
                    throw UnsupportedRequestMethodException();
                }
            }));
        }