Beispiel #1
0
        public async Task UpdateAsync(IMerchant srcMerchant)
        {
            srcMerchant.TrimProperties();

            IMerchant existingMerchant = await _merchantRepository.GetAsync(srcMerchant.Name);

            if (existingMerchant == null)
            {
                throw new MerchantNotFoundException(srcMerchant.Name);
            }

            if (srcMerchant.ApiKey != existingMerchant.ApiKey)
            {
                IReadOnlyList <IMerchant> merchants = await _merchantRepository.FindApiKeyAsync(srcMerchant.ApiKey);

                if (merchants.Any())
                {
                    throw new DuplicateMerchantApiKeyException(srcMerchant.ApiKey);
                }
            }

            if (string.IsNullOrEmpty(srcMerchant.Email))
            {
                srcMerchant.Email = existingMerchant.Email;
            }
            else
            {
                if (!string.IsNullOrEmpty(existingMerchant.Email))
                {
                    throw new MerchantEmailUpdateException(existingMerchant.Id);
                }

                IMerchant emailMerchant = await _merchantRepository.FindEmailAsync(srcMerchant.Email);

                if (emailMerchant != null)
                {
                    throw new DuplicateMerchantEmailException(srcMerchant.Email);
                }
            }

            await _merchantRepository.ReplaceAsync(srcMerchant);

            _log.Info("Merchant updated", srcMerchant);
        }
Beispiel #2
0
        public async Task <IMerchant> CreateAsync(IMerchant merchant)
        {
            merchant.TrimProperties();

            IReadOnlyList <IMerchant> apiKeyMerchants = await _merchantRepository.FindApiKeyAsync(merchant.ApiKey);

            if (apiKeyMerchants.Any())
            {
                throw new DuplicateMerchantApiKeyException(merchant.ApiKey);
            }

            IMerchant emailMerchant = await _merchantRepository.FindEmailAsync(merchant.Email);

            if (emailMerchant != null)
            {
                throw new DuplicateMerchantEmailException(merchant.Email);
            }

            IMerchant createdMerchant = await _merchantRepository.InsertAsync(merchant);

            _log.Info("Merchant created", merchant);

            return(createdMerchant);
        }