Exemple #1
0
        public async Task <IActionResult> AddWallet(AddInvestmentWalletInputModel input)
        {
            try
            {
                if (!this.ModelState.IsValid)
                {
                    var currenciesDto = await this.currenciesService.GetAllAsync();

                    input.Currencies = currenciesDto.Select(c => new CurrencyViewModel
                    {
                        Code       = c.Code,
                        CurrencyId = c.CurrencyId,
                        Name       = c.Name,
                    })
                                       .ToList();

                    return(this.View(input));
                }

                var user = await this.userManager.GetUserAsync(this.User);

                await this.investmentsWalletsService
                .AddAsync(user.Id, input.Name, input.SelectedCurrencyId);

                return(this.Redirect("/Investments/AllInvestments"));
            }
            catch (Exception ex)
            {
                return(this.Redirect($"/Home/Error?message={ex.Message}"));
            }
        }
        public async Task AddWalletPostShouldCreateWalletSuccessfully()
        {
            // Arrange
            this.FillDatabase();
            this.inputModel = new AddInvestmentWalletInputModel
            {
                Name = "Test Investment Wallet",
                SelectedCurrencyId = 2,
            };

            // Act
            var result = await this.controller.AddWallet(this.inputModel);

            // Assert
            var viewResult = Assert.IsType <RedirectResult>(result);

            var createdWallet = this.db.InvestmentWallets.FirstOrDefault(x => x.Name == "Test Investment Wallet");

            Assert.Equal("Test Investment Wallet", createdWallet.Name);
            Assert.Equal(2, createdWallet.CurrencyId);
            Assert.Equal(4, this.db.InvestmentWallets.Count());
        }
Exemple #3
0
        public async Task <IActionResult> AddWallet()
        {
            try
            {
                var currenciesDto = await this.currenciesService.GetAllAsync();

                var model = new AddInvestmentWalletInputModel()
                {
                    Currencies = currenciesDto.Select(c => new CurrencyViewModel
                    {
                        Code       = c.Code,
                        CurrencyId = c.CurrencyId,
                        Name       = c.Name,
                    })
                                 .ToList(),
                };

                return(this.View(model));
            }
            catch (Exception ex)
            {
                return(this.Redirect($"/Home/Error?message={ex.Message}"));
            }
        }