Esempio n. 1
0
        public async Task <ActionResult> UpdateCurrency(UpdateCurrencyModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View("UpdateCurrencyModal", model));
            }

            var result = await CurrencyWriter.UpdateCurrency(model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View("UpdateCurrencyModal", model));
            }

            return(CloseModalSuccess(result.Message));
        }
Esempio n. 2
0
        public async Task UpdateCurrencyWithMissingFieldsInvalidModelTest()
        {
            var user = await CreateUser($"{Guid.NewGuid()}Bob", Roles.ClientAdmin);

            var model = new UpdateCurrencyModel
            {
                Description = "Australian Dollar"
            };

            var createResult = await Browser.Post("/v1/currency", with =>
            {
                with.JsonBody(model);
                with.User(user);
            });

            createResult.StatusCode.Should().Be(HttpStatusCode.BadRequest);
        }
        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);
            }
        }
        public async Task UpdateCurrencyTest()
        {
            var currency = GetDefaultCurrency();

            _efContextMock
            .MockAsyncQueryable(new [] { currency }.AsQueryable(), d => d.Currency)
            .Setup(c => c.FindAsync(currency.Id))
            .ReturnsAsync(currency);

            var model = new UpdateCurrencyModel
            {
                Code        = "AUD",
                Description = "Australian Dollar",
                Symbol      = "$"
            };

            await _service.UpdateCurrency(currency.Id, model);

            _efContextMock.Verify(m => m.SaveChangesAsync(It.IsAny <CancellationToken>()), Times.Once);
        }
Esempio n. 5
0
        public async Task <WriterResult <bool> > UpdateCurrency(string userId, UpdateCurrencyModel model)
        {
            using (var context = DataContextFactory.CreateContext())
            {
                var currency = await context.Currency.FirstOrDefaultNoLockAsync(c => c.Id == model.Id);

                if (currency == null)
                {
                    return(WriterResult <bool> .ErrorResult("Currency {0} not found.", model.Id));
                }

                var existing = await context.Currency.FirstOrDefaultNoLockAsync(c => c.Id != currency.Id && (c.Name == model.Name || c.Symbol == model.Symbol));

                if (existing != null)
                {
                    return(WriterResult <bool> .ErrorResult("Currency with {0} already exists.", existing.Name == model.Name?$"Name '{model.Name}'" : $"Symbol '{model.Symbol}'"));
                }

                currency.IsEnabled        = model.IsEnabled;
                currency.MaxTrade         = model.MaxTrade;
                currency.MaxWithdraw      = model.MaxWithdraw;
                currency.MinBaseTrade     = model.MinBaseTrade;
                currency.MinConfirmations = model.MinConfirmations;
                currency.MinTrade         = model.MinTrade;
                currency.MinWithdraw      = model.MinWithdraw;
                currency.Name             = model.Name;
                currency.Status           = model.Status;
                currency.StatusMessage    = model.StatusMessage;
                currency.TradeFee         = model.TradeFee;
                currency.TransferFee      = model.TransferFee;
                currency.WithdrawFee      = model.WithdrawFee;
                currency.WithdrawFeeType  = model.WithdrawFeeType;
                currency.ColdBalance      = model.ColdBalance;
                currency.MarketSortOrder  = model.MarketSortOrder;
                currency.Algo             = model.Algo;
                currency.InterfaceType    = model.InterfaceType;
                currency.Type             = model.Type;
                currency.IsFaucetEnabled  = model.IsFaucetEnabled;
                currency.FaucetPayment    = model.FaucetPayment;
                currency.FaucetMax        = model.FaucetMax;

                // Id the symbol has changed update the tradepair names
                if (currency.Symbol != model.Symbol)
                {
                    currency.Symbol = model.Symbol;
                    var tradePairs = await context.TradePair
                                     .Include(testc => testc.Currency1)
                                     .Include(testc => testc.Currency2)
                                     .Where(t => t.CurrencyId1 == model.Id || t.CurrencyId2 == model.Id)
                                     .ToListNoLockAsync();

                    foreach (var tradePair in tradePairs)
                    {
                        tradePair.Name = tradePair.CurrencyId1 == model.Id
                                                        ? $"{currency.Symbol}_{tradePair.Currency2.Symbol}"
                                                        : $"{tradePair.Currency1.Symbol}_{currency.Symbol}";
                    }
                }

                await context.SaveChangesAsync();

                return(WriterResult <bool> .SuccessResult());
            }
        }