public async Task <IActionResult> EditWallet(int id) { try { var currenciesDto = await this.currenciesService.GetAllAsync(); var currentCurrency = await this.investmentsWalletsService.GetInvestmentCurrencyAsync(id); var model = new EditInvestmentWalletInputModel() { Id = id, Name = await this.investmentsWalletsService.GetInvestmentWalletNameAsync(id), SelectedCurrency = new CurrencyViewModel { CurrencyId = currentCurrency.CurrencyId, Code = currentCurrency.Code, Name = currentCurrency.Name, }, 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}")); } }
public async Task EditWalletGetShouldEditWalletSucessfully() { // Arrange this.FillDatabase(); this.editModel = new EditInvestmentWalletInputModel { Id = 2, Name = "Edited Wallet Name", SelectedCurrency = new CurrencyViewModel { CurrencyId = 3, Name = "Euro", Code = "EUR", }, }; // Act var result = await this.controller.EditWallet(this.editModel); // Assert var redirectResult = Assert.IsType <RedirectResult>(result); var editedWallet = this.db.InvestmentWallets.FirstOrDefault(x => x.Id == 2); Assert.Equal("Edited Wallet Name", editedWallet.Name); Assert.Equal(3, editedWallet.CurrencyId); }
public async Task <IActionResult> EditWallet(EditInvestmentWalletInputModel input) { try { if (!this.ModelState.IsValid) { var currenciesDto = await this.currenciesService.GetAllAsync(); var currentCurrency = await this.investmentsWalletsService.GetInvestmentCurrencyAsync(input.Id); input.Currencies = currenciesDto.Select(c => new CurrencyViewModel { Code = c.Code, CurrencyId = c.CurrencyId, Name = c.Name, }) .ToList(); input.SelectedCurrency = new CurrencyViewModel { CurrencyId = currentCurrency.CurrencyId, Code = currentCurrency.Code, Name = currentCurrency.Name, }; return(this.View(input)); } var user = await this.userManager.GetUserAsync(this.User); await this.investmentsWalletsService.EditAsync(user.Id, input.Id, input.SelectedCurrency.CurrencyId, input.Name); return(this.Redirect("/Investments/AllInvestments")); } catch (Exception ex) { return(this.Redirect($"/Home/Error?message={ex.Message}")); } }