public void ChangeMargin(double amount, DateTimeOffset time, string note, AccountChangeType type) { var change = new AccountChange(UsedMargin, amount, time, note, type); _marginChanges.Add(change); UsedMargin = change.NewValue; CheckForMarginCall(); }
public IChangeService AddChange(UserAccount account, string fieldName, string previous, string updated) { //get the current time and update details for the AccountChange DateTime timestamp = DateTime.Now; Guid identifier = account.Identifier; AccountChange change = new AccountChange(identifier, fieldName, previous, updated, timestamp); //add the change to the dictionary changeHistory.Add(change); return(this); }
public IActionResult Change(AccountChange model) { int? UserID = HttpContext.Session.GetInt32("LOGGED_IN_USER"); User LoggedIn = _context.Users.SingleOrDefault(user => user.id == UserID); DateTime now = DateTime.Now; if (ModelState.IsValid) { if (model.change == "Deposit") { //Add item to balance change table Account BalanceChange = new Account { change = model.amount, Users_id = (int)UserID, date = now }; _context.Add(BalanceChange); _context.SaveChanges(); //Update balance which is under user LoggedIn.balance += model.amount; _context.SaveChanges(); return(RedirectToAction("Account", new { id = UserID })); } if (model.change == "Withdraw") { //Update balance which is under user LoggedIn.balance -= model.amount; if (LoggedIn.balance < 0) { TempData["error"] = "You cannot withdraw past 0"; return(RedirectToAction("Account", new { id = UserID })); } _context.SaveChanges(); Account BalanceChange = new Account { change = model.amount - (model.amount * 2), Users_id = (int)UserID, date = now }; _context.Add(BalanceChange); _context.SaveChanges(); return(RedirectToAction("Account", new { id = UserID })); } } ViewBag.errors = ModelState.Values; return(RedirectToAction("Account", new { id = UserID })); }
private byte[] Send(byte[] data, out long size) { SendResponseError error; SendMoney money = data.DeserializeObject <SendMoney>(out size); ConnectedClient cl = connectedClients[money.sessionId]; if (cl == null) { Console.WriteLine("Unconnected!" + money.sessionId); } bool withdraw = money.to.Length == 0; int to = 0; if (!withdraw) { int i; for (i = 0; i < clients.Count; i++) { if (clients[i].Id == money.to) { to = i; break; } } if (i == clients.Count) { error = SendResponseError.SEND_INVAL_ID; return(CreateMessage(ServerProtocol.svc_sendresponse, error.SerializeToByteArray())); } } if (clients[cl.Id].Account > money.value) { error = SendResponseError.SEND_SUCCESS; clients[cl.Id].Account -= money.value; if (!withdraw) { clients[to].Account += money.value; } AccountChange acc = new AccountChange() { from = clients[cl.Id].Id, isSent = false, loginId = money.to, account = -money.value }; globalHistory.Add(acc); if (clients[cl.Id].history != null) { clients[cl.Id].history.Add(acc); } if (!withdraw) { AccountChange acc2 = new AccountChange() { from = clients[to].Id, isSent = true, loginId = clients[cl.Id].Id, account = money.value }; globalHistory.Add(acc2); if (clients[to].history != null) { clients[to].history.Add(acc2); } } } else { error = SendResponseError.SEND_NOTENOUGH; } return(CreateMessage(ServerProtocol.svc_sendresponse, error.SerializeToByteArray())); }