public async Task <IActionResult> ExchangeMoney([FromRoute] int id, [FromBody] ExchangeMoney money) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(ModelState)); } try { var fromCurrency = await _currencyRepository.GetAsync(money.FromCurrencyId); var toCurrency = await _currencyRepository.GetAsync(money.ToCurrencyId); var user = await _userRepository.GetByIdIncludingBalanceAsync(id); user.Balance.Exchange(new Money(fromCurrency, money.Amount), toCurrency); await _userRepository.UpdateBalanceAsync(user); return(Ok(StatusCodes.Status200OK)); } catch (Exception e) { //log error return(StatusCode(StatusCodes.Status500InternalServerError));; } }
public void When_Exhanging_Money() { var fixture = new Fixture(); var userId = 1; var currencyId = 1; var currencyId2 = 2; var currencyResult1 = new Currency(currencyId, "USD", (decimal)1); var currencyResult = new Currency(currencyId, "EUR", (decimal)2); var balance = new Balance(); balance.AddMoney(new Money(currencyResult, 10)); var dataResult = userRepository.Add(new User(userId, "test", balance)); var param = new ExchangeMoney() { FromCurrencyId = currencyId, ToCurrencyId = 2, Amount = 10 }; var user = _userDataManager.Setup(x => x.GetUserBalance(userId, currencyId)).Returns(dataResult); _userDataManager.Setup(x => x.GetCurrency(currencyId)).Returns(currencyResult1); _userDataManager.Setup(x => x.GetCurrency(currencyId2)).Returns(currencyResult); _userDataManager.Setup(x => x.UpdateUserBalance(dataResult)); var result = userRepository.ExchangeMoney(param, userId); Assert.IsNotNull(result); }
public IActionResult ExchangeMoney(int userId, ExchangeMoney exhangeMoney) { var result = _userRepository.ExchangeMoney(exhangeMoney, userId); if (result == true) { return(Ok(StatusCodes.Status200OK)); } else { return(BadRequest(StatusCodes.Status500InternalServerError)); } }
/// /// <summary> /// 登録ボタンを押下時データベースにInsertする /// </summary> public void Save() { if (ErrorCheck()) { if (ExchangeLabel.Text != ExchangeMoney.Text) { trrnbl.ShowMessage("E181"); ExchangeCount.Focus(); } else { if (trrnbl.ShowMessage("Q101") == DialogResult.Yes) { DataTable dt = new DataTable(); dt = trrnbl.SimpleSelect1("70", ChangeDate.Replace("/", "-"), storeCD); if (dt.Rows.Count > 0) { trrnbl.ShowMessage("E252"); } valid = false; mre = DepositHistoryEnity(); if (trrnbl.TempoRegiRyougaeNyuuryoku_Insert_Update(mre)) { trrnbl.ShowMessage("I101"); RunConsole(); //exeRun ExchangeDenomination.SelectedValue = "-1"; ExchangeMoney.Clear(); ExchangeCount.Clear(); ExchangeLabel.Text = ""; Remark.Clear(); ExchangeMoney.Focus(); } else { trrnbl.ShowMessage("S001"); } } else { PreviousCtrl.Focus(); //Remark.Focus(); } } } }
public bool?ExchangeMoney(ExchangeMoney exhangeMoney, int userId) { var fromCurrency = _userDataManager.GetCurrency(exhangeMoney.FromCurrencyId); var toCurrency = _userDataManager.GetCurrency(exhangeMoney.ToCurrencyId); var fromCurrencyUser = _userDataManager.GetUserBalance(userId, fromCurrency.CurrencyId); var toCurrencyUser = _userDataManager.GetUserBalance(userId, toCurrency.CurrencyId); var moneyCharge = new Money(fromCurrency, exhangeMoney.Amount); var moneyAdd = new Money(fromCurrency, exhangeMoney.Amount); fromCurrencyUser.Balance.ChargeMoney(moneyCharge); _userDataManager.UpdateUserBalance(fromCurrencyUser); var exchange = new Money(fromCurrency, exhangeMoney.Amount); var result = toCurrencyUser.Balance.ExchangeMoney(exchange, toCurrency); _userDataManager.UpdateUserBalance(toCurrencyUser); return(result); }
private void SetRequireField() { ExchangeMoney.Require(true); ExchangeDenomination.Require(true); ExchangeCount.Require(true); }