public async Task <IWriterResult> DelistCurrency(string adminUserId, UpdateListingStatusModel model) { model.ListingStatus = CurrencyListingStatus.Delisted; var writerResult = await UpdateListingStatus(adminUserId, model); if (!writerResult.Success) { return(writerResult); } using (var context = ExchangeDataContextFactory.CreateContext()) { // Checks for closing trade pairs only as it's expected to be in 'delisting' before it's delisted. var tradePairs = await context.TradePair.Where(t => t.Status == TradePairStatus.Closing && (t.CurrencyId1 == model.CurrencyId || t.CurrencyId2 == model.CurrencyId)).ToListNoLockAsync(); foreach (var tradePair in tradePairs) { tradePair.Status = TradePairStatus.Closed; } using (var adminContext = DataContextFactory.CreateContext()) { adminContext.LogActivity(adminUserId, $"Delisted Currency: {model.Name}"); await adminContext.SaveChangesAsync().ConfigureAwait(false); } await context.SaveChangesAsync().ConfigureAwait(false); await CacheService.InvalidateAsync(CacheKey.Currencies(), CacheKey.CurrencyInfo(), CacheKey.CurrencyDataTable(), CacheKey.CurrencySummary(model.CurrencyId)).ConfigureAwait(false); } writerResult.Message = "Successfully delisted currency."; return(writerResult); }
private async Task <List <CurrencyModel> > GetOrCacheCurrencies() { var cacheResult = await CacheService.GetOrSetHybridAsync(CacheKey.Currencies(), TimeSpan.FromMinutes(10), async() => { using (var context = ExchangeDataContextFactory.CreateReadOnlyContext()) { var summary = await context.Currency .AsNoTracking() .Where(t => t.IsEnabled) .Select(currency => new CurrencyModel { CurrencyId = currency.Id, Name = currency.Name, Symbol = currency.Symbol, Connections = currency.Connections, Status = currency.Status, StatusMessage = currency.StatusMessage, ListingStatus = currency.ListingStatus, Version = currency.Version, AlgoType = currency.Info.AlgoType, BaseAddress = currency.BaseAddress, Block = currency.Block, BlockTime = currency.Info.BlockTime, Errors = currency.Errors, FeaturedExpires = currency.FeaturedExpires, TippingExpires = currency.TippingExpires, RewardsExpires = currency.RewardsExpires, MinBaseTrade = currency.MinBaseTrade, MinConfirmations = currency.MinConfirmations, NetworkType = currency.Info.NetworkType, PoolFee = currency.PoolFee, Summary = currency.Info.Description, TradeFee = currency.TradeFee, Type = currency.Type, TipMin = currency.MinTip, WithdrawFee = currency.WithdrawFee, WithdrawFeeType = currency.WithdrawFeeType, WithdrawMax = currency.MaxWithdraw, WithdrawMin = currency.MinWithdraw, Website = currency.Info.Website, Rank = currency.Rank, QrFormat = currency.Settings.QrFormat, DepositInstructions = currency.Settings.DepositInstructions, DepositMessage = currency.Settings.DepositMessage, DepositMessageType = currency.Settings.DepositMessageType, WithdrawInstructions = currency.Settings.WithdrawInstructions, WithdrawMessage = currency.Settings.WithdrawMessage, WithdrawMessageType = currency.Settings.WithdrawMessageType, AddressType = currency.Settings.AddressType, CurrencyDecimals = currency.Settings.Decimals }).OrderBy(c => c.Name) .ToListNoLockAsync().ConfigureAwait(false); return(summary); } }).ConfigureAwait(false); return(cacheResult); }
public async Task <IWriterResult> UpdateCurrency(string adminUserId, UpdateCurrencyModel model) { try { using (var context = ExchangeDataContextFactory.CreateContext()) { var currency = await context.Currency.Where(c => c.Id == model.Id).FirstOrDefaultNoLockAsync().ConfigureAwait(false); if (currency == null) { return(new WriterResult(false, "Currency not found")); } currency.PoolFee = model.PoolFee; currency.TradeFee = model.TradeFee; currency.WithdrawFee = model.WithdrawFee; currency.WithdrawFeeType = model.WithdrawFeeType; currency.MinWithdraw = model.WithdrawMin; currency.MaxWithdraw = model.WithdrawMax; currency.MinTip = model.TipMin; currency.MinBaseTrade = model.MinBaseTrade; currency.MinConfirmations = model.MinConfirmations; currency.Status = model.Status; currency.StatusMessage = model.StatusMessage; currency.ListingStatus = model.ListingStatus; using (var adminContext = DataContextFactory.CreateContext()) { adminContext.LogActivity(adminUserId, $"Updated Currency: {currency.Symbol}"); } await context.SaveChangesAsync().ConfigureAwait(false); await CacheService.InvalidateAsync(CacheKey.Currencies(), CacheKey.CurrencyInfo(), CacheKey.CurrencyDataTable(), CacheKey.CurrencySummary(model.Id)).ConfigureAwait(false); return(new WriterResult(true, "Succesfully updated currency settings.")); } } catch (Exception) { return(null); } }
private async Task <IWriterResult> UpdateListingStatus(string adminUserId, UpdateListingStatusModel model) { try { using (var context = ExchangeDataContextFactory.CreateContext()) { var currency = await context.Currency.Where(c => c.Id == model.CurrencyId).FirstOrDefaultNoLockAsync().ConfigureAwait(false); if (currency == null) { return(new WriterResult(false, "Currency not found")); } var oldStatus = currency.ListingStatus; currency.StatusMessage = model.StatusMessage; currency.ListingStatus = model.ListingStatus; currency.Settings.DelistOn = model.DelistOn; using (var adminContext = DataContextFactory.CreateContext()) { adminContext.LogActivity(adminUserId, $"Updated Currency listing status from : {oldStatus} to: {model.ListingStatus}"); await adminContext.SaveChangesAsync().ConfigureAwait(false); } await context.SaveChangesAsync().ConfigureAwait(false); await CacheService.InvalidateAsync(CacheKey.Currencies(), CacheKey.CurrencyInfo(), CacheKey.CurrencyDataTable(), CacheKey.CurrencySummary(model.CurrencyId)).ConfigureAwait(false); return(new WriterResult(true, "Succesfully updated listing status.")); } } catch (Exception) { return(null); } }