Esempio n. 1
0
        public Task StoreProfile(Profile profile, CancellationToken cancellationToken)
        {
            Ensure.Any.IsNotNull(profile, nameof(profile));

            var adapter = new ProfileAdapter(profile);

            return(InsertOrReplaceEntity(TableName, adapter, cancellationToken));
        }
Esempio n. 2
0
        public async Task <Profile> GetProfile(Guid profileId, CancellationToken cancellationToken)
        {
            Ensure.Guid.IsNotEmpty(profileId, nameof(profileId));

            var partitionKey = ProfileAdapter.BuildPartitionKey(profileId);
            var rowKey       = ProfileAdapter.BuildRowKey(profileId);
            var operation    = TableOperation.Retrieve <ProfileAdapter>(partitionKey, rowKey);
            var table        = GetTable(TableName);

            var result = await table.ExecuteAsync(operation, null, null, cancellationToken).ConfigureAwait(false);

            if (result.HttpStatusCode == 404)
            {
                return(null);
            }

            var entity = (ProfileAdapter)result.Result;

            return(entity.Value);
        }
Esempio n. 3
0
        public async Task <Profile> BanProfile(
            Guid profileId,
            DateTimeOffset bannedAt,
            CancellationToken cancellationToken)
        {
            Ensure.Guid.IsNotEmpty(profileId, nameof(profileId));

            var partitionKey = ProfileAdapter.BuildPartitionKey(profileId);
            var rowKey       = ProfileAdapter.BuildRowKey(profileId);

            var operation = TableOperation.Retrieve <ProfileAdapter>(partitionKey, rowKey);
            var table     = GetTable(TableName);

            var result = await table.ExecuteAsync(operation, null, null, cancellationToken).ConfigureAwait(false);

            if (result.HttpStatusCode == 404)
            {
                return(null);
            }

            var entity = (ProfileAdapter)result.Result;

            if (entity.Value.BannedAt.HasValue)
            {
                // This profile has already been banned
                return(null);
            }

            entity.Value.BannedAt = bannedAt;

            var updateOperation = TableOperation.Replace(entity);

            await table.ExecuteAsync(updateOperation).ConfigureAwait(false);

            return(entity.Value);
        }