public async Task SaveChangesAsync(Core.Currency.Currency[] currencies)
        {
            if (currencies == null)
            {
                throw new ArgumentNullException(nameof(currencies));
            }

            var pkMap = new PrimaryKeyResolvingMap();

            using (var repository = _repositoryFactory())
            {
                //Ensure that only one Primary currency
                if (currencies.Any(x => x.IsPrimary))
                {
                    var oldPrimaryCurrency = await repository.Currencies.FirstOrDefaultAsync(x => x.IsPrimary);

                    if (oldPrimaryCurrency != null)
                    {
                        oldPrimaryCurrency.IsPrimary = false;
                    }
                }

                foreach (var currency in currencies)
                {
                    var sourceEntry = AbstractTypeFactory <CurrencyEntity> .TryCreateInstance().FromModel(currency);

                    var targetEntry = await repository.Currencies.FirstOrDefaultAsync(x => x.Code == currency.Code);

                    if (targetEntry == null)
                    {
                        repository.Add(sourceEntry);
                    }
                    else
                    {
                        sourceEntry.Patch(targetEntry);
                    }
                }

                await repository.UnitOfWork.CommitAsync();

                CurrencyCacheRegion.ExpireRegion();
            }
        }
        public async Task DeleteCurrenciesAsync(string[] codes)
        {
            using (var repository = _repositoryFactory())
            {
                var currencyEntities = await repository.Currencies.Where(x => codes.Contains(x.Code)).ToArrayAsync();

                foreach (var currency in currencyEntities)
                {
                    if (currency.IsPrimary)
                    {
                        throw new ArgumentException("Unable to delete primary currency");
                    }

                    repository.Remove(currency);
                }

                await repository.UnitOfWork.CommitAsync();

                CurrencyCacheRegion.ExpireRegion();
            }
        }