Esempio n. 1
0
        public async Task UpsertAsync(AccountCardDetails cardDetails, CancellationToken ct = default(CancellationToken))
        {
            //if it exists
            var existingDetails = await GetAsync(cardDetails.AccountId, ct);

            if (existingDetails != null)
            {
                //TODO: Compare byte[] versions
                AggregateLock aggregateLock = null;
                try
                {
                    //lock it
                    aggregateLock = await LockAsync(cardDetails.AccountId.ToString(), "SYS", ct);

                    //update it
                    await UpdateAsync(cardDetails, aggregateLock, ct);
                }
                finally
                {
                    if (aggregateLock != null)
                    {
                        await aggregateLock.ReleaseAsync();
                    }
                }
            }
            else
            {
                //add it
                await AddAsync(cardDetails, ct);
            }
        }
Esempio n. 2
0
        public async Task UpsertAsync(AccountCardDetails cardDetails, CancellationToken ct = default(CancellationToken))
        {
            //if it exists
            var existingDetails = await GetAsync(cardDetails.AccountId, ct);

            if (existingDetails != null)
            {
                AggregateLock aggregateLock = null;
                try
                {
                    //lock it
                    aggregateLock = await LockAsync(cardDetails.AccountId.ToString(), "SYS", ct);

                    //TODO: We should really check for later timestamp before updating

                    //TODO: If the lock returned the card details we might be able to avoid this
                    var toChange = await GetAsync(cardDetails.AccountId, ct);

                    toChange.Name               = cardDetails.Name;
                    toChange.Version            = cardDetails.Version;
                    toChange.CardNumber         = cardDetails.CardNumber;
                    toChange.ZipCode            = cardDetails.ZipCode;
                    toChange.CardSecurityCode   = cardDetails.CardSecurityCode;
                    toChange.FirstLineOfAddress = cardDetails.FirstLineOfAddress;

                    //update it
                    await UpdateAsync(ct);
                }
                finally
                {
                    if (aggregateLock != null)
                    {
                        await aggregateLock.ReleaseAsync();
                    }
                }
            }
            else
            {
                //add it
                await AddAsync(cardDetails, ct);
            }
        }
Esempio n. 3
0
 private async Task UpdateAsync(AccountCardDetails cardDetails, AggregateLock aggregateLock, CancellationToken ct = default(CancellationToken))
 {
     await _unitOfWork.AddAsync(cardDetails, ct);
 }