如何解决如何将金额从一个用户余额转移到另一用户余额?
<script>
function Account(UserId,Balance) {
this.UserId = UserId;
this.Balance = Balance;
}
Account.prototype.deposit = function (amount) {
if (this._isPositive(amount)) {
this.balance += amount;
console.info(`Deposit: ${this.name} new balance is ${this.balance}`);
return true;
}
return false;
}
Account.prototype.withdraw = function (amount) {
if (this._isAllowed(amount)) {
this.balance -= amount;
console.info(`Withdraw: ${this.name} new balance is ${this.balance}`);
return true;
}
return false;
}
Account.prototype.transfer = function (amount,account) {
if (this.withdraw(amount) && account.deposit(amount)) {
console.info(`Transfer: ${amount} has been moved from ${this.name} to ${account.name}`);
return true;
}
return false;
}
Account.prototype._isPositive = function (amount) {
const isPositive = amount > 0;
if (!isPositive) {
console.error('Amount must be positive!');
return false;
}
return true;
}
Account.prototype._isAllowed = function (amount) {
if (!this._isPositive(amount)) return false;
const isAllowed = this.balance - amount >= 0;
if (!isAllowed) {
console.error('You have insufficent funds!');
return false;
}
return true;
}
function transferring() {
mary21.transfer(100.00,john456);
}
</script>
我正在尝试将金额从一个用户余额转移到另一个用户余额。我可以知道如何在我的项目中使用此javascript。我正在使用.Net MVC,所以不确定在View或Controller中完成事务。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。