public async Task ReplaceAsync(IMerchant merchant)
        {
            var entity = new MerchantEntity(
                MerchantEntity.ById.GeneratePartitionKey(merchant.Name),
                MerchantEntity.ById.GenerateRowKey(merchant.Name));

            Mapper.Map(merchant, entity);

            entity.ETag = "*";

            await _storage.ReplaceAsync(entity);

            if (!string.IsNullOrEmpty(merchant.Email))
            {
                var existingEmailIndex = await _emailIndexStorage.GetDataAsync(
                    MerchantEntity.IndexByEmail.GeneratePartitionKey(merchant.Email),
                    MerchantEntity.IndexByEmail.GenerateRowKey());

                if (existingEmailIndex == null)
                {
                    var newEmailIndex = MerchantEntity.IndexByEmail.Create(entity);

                    await _emailIndexStorage.InsertThrowConflict(newEmailIndex);
                }
            }
        }
            public static MerchantEntity Create(IMerchant src)
            {
                var entity = new MerchantEntity(GeneratePartitionKey(src.Name), GenerateRowKey(src.Name));

                Mapper.Map(src, entity);

                return(entity);
            }
        public async Task <IMerchant> FindEmailAsync(string email)
        {
            AzureIndex index = await _emailIndexStorage.GetDataAsync(
                MerchantEntity.IndexByEmail.GeneratePartitionKey(email),
                MerchantEntity.IndexByEmail.GenerateRowKey());

            MerchantEntity entity = await _storage.GetDataAsync(index);

            return(Mapper.Map <Merchant>(entity));
        }
        public async Task DeleteAsync(string merchantName)
        {
            MerchantEntity merchantEntity = await _storage.DeleteAsync(
                MerchantEntity.ById.GeneratePartitionKey(merchantName),
                MerchantEntity.ById.GenerateRowKey(merchantName));

            if (merchantEntity == null)
            {
                throw new MerchantNotFoundException(merchantName);
            }

            await _emailIndexStorage.DeleteAsync(
                MerchantEntity.IndexByEmail.GeneratePartitionKey(merchantEntity.Email),
                MerchantEntity.IndexByEmail.GenerateRowKey());
        }
 public static AzureIndex Create(MerchantEntity entity)
 {
     return(AzureIndex.Create(
                GeneratePartitionKey(entity.Email),
                GenerateRowKey(), entity));
 }