public async Task <List <string> > invalidat_cash([FromBody] CashRequest cashRequest) { List <cash> cashs = new List <cash>(); List <int> cash_ids = new List <int>(); List <cash> out_cash = new List <cash>(); foreach (var cashStr in cashRequest.cashs) { var cash = cashValidator.CashFromString(cashStr); cash_ids.Add(cash.id.Value); } cashs = await db.cashs .Where(a => cash_ids.Contains(a.id) && !a.invalidated_by.Any()) .ToListAsync(); if (cashs.Count != cashRequest.cashs.Count) { throw new Exception("money count does not match"); } if (cashRequest.amounts .Sum() != cashs.Sum(b => b.amount)) { throw new Exception("input money must have same amount as output money."); } foreach (var amount in cashRequest.amounts) { var cash = new cash { amount = amount, created_at = DateTimeOffset.UtcNow, digital = true, invalidated_by = new List <cash_invalidation>(), invalidates = cash_ids.Select(a => new cash_invalidation() { invalidated_cash_id = a }).ToList() }; out_cash.Add(cash); db.cashs.Add(cash); } await db.SaveChangesAsync(); return(out_cash .Select(CashController.cash.Compile()) .Select(a => cashValidator.CashToString(a)) .ToList()); }
public async Task <string> test_money(int amount = 50) { var cash = new cash { amount = amount, created_at = DateTimeOffset.UtcNow, digital = true, invalidated_by = new List <cash_invalidation>() }; db.cashs.Add(cash); await db.SaveChangesAsync(); return(cashValidator.CashToString(CashController.cash.Invoke(cash))); }
public void AddCashItem(cash item) { if (capacity >= current + item.Value && GemItemsValue >= CashItemsValue + item.Value) { var cashItems = GetCashItems(); if (cashItems.Any(gi => gi.Key == item.Key)) { cashItems.Single(gi => gi.Key == item.Key).IncreaseValue(item.Value); } else { bag1.Add(item); } current += item.Value; } }
private static void InsertItem(string key, long value, bag bag) { if (key.Length == 3) { cash cash = new cash(key, value); bag.AddCashItem(cash); } else if (key.Length >= 4 && key.ToLower().EndsWith("gem")) { gem gem = new gem(key, value); bag.AddGemItem(gem); } else if (key.ToLower().Equals("gold")) { gold gold = new gold(key, value); bag.AddGoldItem(gold); } }
// Set up click event handlers for each of the buttons that open // a new in_gui dialog for the different types of transactions. private void cashButton_Click(object sender, EventArgs e) { cash c = new cash(cbkName); c.cashSub(); }