public async Task <WriterResult <bool> > CreateCurrency(string userId, CreateCurrencyModel model) { using (var context = DataContextFactory.CreateContext()) { var existing = await context.Currency.FirstOrDefaultNoLockAsync(c => 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}'")); } existing = await context.Currency.FirstOrDefaultNoLockAsync(c => c.WalletPort == model.WalletPort && c.WalletHost == model.WalletHost); if (existing != null) { return(WriterResult <bool> .ErrorResult("Wallet with RPC settings {0}:{1} already exists.", model.WalletHost, model.WalletPort)); } var entity = new Entity.Currency { IsEnabled = model.IsEnabled, MaxTrade = model.MaxTrade, MaxWithdraw = model.MaxWithdraw, MinBaseTrade = model.MinBaseTrade, MinConfirmations = model.MinConfirmations, MinTrade = model.MinTrade, MinWithdraw = model.MinWithdraw, Name = model.Name, Status = model.Status, StatusMessage = model.StatusMessage, Symbol = model.Symbol, TradeFee = model.TradeFee, TransferFee = model.TransferFee, WithdrawFee = model.WithdrawFee, WithdrawFeeType = model.WithdrawFeeType, WalletHost = model.WalletHost, WalletPass = model.WalletPass, WalletPort = model.WalletPort, WalletUser = model.WalletUser, ColdBalance = 0m, MarketSortOrder = model.MarketSortOrder, Algo = model.Algo, InterfaceType = model.InterfaceType, Type = model.Type, IsFaucetEnabled = model.IsFaucetEnabled, FaucetMax = model.FaucetMax, FaucetPayment = model.FaucetPayment }; context.Currency.Add(entity); await context.SaveChangesAsync(); return(WriterResult <bool> .SuccessResult()); } }
public async Task <ActionResult> Create(CreateCurrencyModel model) { if (!ModelState.IsValid) { return(View("CreateCurrencyModal", model)); } var result = await CurrencyWriter.CreateCurrency(User.Id(), model); if (!ModelState.IsWriterResultValid(result)) { return(View("CreateCurrencyModal", model)); } return(CloseModal()); }
public async Task CreateDefaultCurrencyValidationTest() { var user = await CreateUser($"{Guid.NewGuid()}Bob", Roles.ClientAdmin); var model = new CreateCurrencyModel { Description = "United States Dollar", Symbol = "$" }; var createResult = await Browser.Post("/v1/currency", with => { with.JsonBody(model); with.User(user); }); createResult.StatusCode.Should().Be(HttpStatusCode.BadRequest); }
public async Task TestCreate() { var user = await CreateUser($"{Guid.NewGuid()}Bob", Roles.ClientAdmin); var createModel = new CreateCurrencyModel { Code = "CAD", Description = "Canadian Dollar", Symbol = "$", }; var createResult = await Browser.Post("/v1/currency", with => { with.JsonBody(createModel); with.User(user); }); Deserialize <Currency>(createResult, HttpStatusCode.Created); }