protected Account(string name, Currency currency, double startBalance) { //default dollars this.ClientName = name; this.currency = currency; try { MD5 md5 = MD5.Create(); this.AccountId = CustomMD5.GetMd5Hash(md5, String.Format($"User:{name}")); //Start balance 100 dollars //TODO: converter double balance = startBalance * (double)CurrencyProcessor.convertCoeficient(this.currency); if (balance < START_BALANCE) { throw new Exception("Invalid starting deposit"); } } catch (Exception e) { Console.WriteLine(e); return; } this.Balance = startBalance; }
public virtual void paymentslashtransaction(double money, string purpose, string receiverId, Currency currency = Currency.DOLLAR) { double defaultBalance = this.Balance * (double)CurrencyProcessor.convertCoeficient(this.currency); double defaultMoney = money * (double)CurrencyProcessor.convertCoeficient(currency); Transaction transaction; try { //default currency is DOLLAR if (defaultBalance < defaultMoney) { throw new Exception("Your balance has not money for this transaction"); } transaction = new Transaction(this.AccountId, money, purpose, receiverId, currency); this.bt += transaction.transact; if (!bt.Invoke()) { throw new Exception("Something went wrong"); } } catch (Exception ex) { Console.WriteLine(ex.Message); return; } if (this.currency == currency) { this.Balance -= money; } else { this.Balance -= defaultMoney / (double)CurrencyProcessor.convertCoeficient(this.currency); } transaction.Verified = true; this.journal.Add(transaction); AccountXmlLoader.update(this); }
public bool transact() { try { if (!AccountXmlLoader.checkIfExists(this.ReceiverID)) { throw new Exception("Receiver not found"); } Account sender = AccountXmlLoader.pull(this.SenderID); Account receiver = AccountXmlLoader.pull(this.ReceiverID); //no commision if (receiver.currency == this.currency) { receiver.Balance += this.Sum; } else { double defaultvalue = this.Sum * (double)CurrencyProcessor.convertCoeficient(this.currency); double receiverCurrencyValue = defaultvalue / (double)CurrencyProcessor.convertCoeficient(receiver.currency); receiver.Balance += receiverCurrencyValue; } AccountXmlLoader.update(receiver); this.Verified = true; } catch (Exception ex) { Console.WriteLine(ex.Message); this.Verified = false; } finally { TransactionXmlLoader.push(this); } return(this.Verified); }
public double checkDefaultBalance() { return(Balance * (double)CurrencyProcessor.convertCoeficient(currency)); }