コード例 #1
0
        /// <inheritdoc />
        public async Task <bool> Add(string owner, ResourceSet resourceSet, CancellationToken cancellationToken)
        {
            await using var session = _sessionFactory();
            session.Store(OwnedResourceSet.FromResourceSet(resourceSet, owner));
            await session.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            return(true);
        }
コード例 #2
0
        /// <inheritdoc />
        public async Task <Option> Update(ResourceSet resourceSet, CancellationToken cancellationToken)
        {
            await using var session = _sessionFactory();
            var existing = await session.LoadAsync <OwnedResourceSet>(resourceSet.Id, cancellationToken).ConfigureAwait(false);

            if (existing == null)
            {
                return(new ErrorDetails
                {
                    Status = HttpStatusCode.NotFound,
                    Title = ErrorCodes.NotUpdated,
                    Detail = SharedStrings.ResourceCannotBeUpdated
                });
            }
            session.Update(OwnedResourceSet.FromResourceSet(resourceSet, existing.Owner));
            await session.SaveChangesAsync(cancellationToken).ConfigureAwait(false);

            return(new Option.Success());
        }