private void SavePaymentSlip() { using (var db = new PaymentSlipContext()) { if (db.Accounts.Any(a => a.IBAN == tbxIBANPayer.Text)) { var account = db.Accounts.Where(a => a.IBAN == tbxIBANPayer.Text).SingleOrDefault(); var transacton = Transaction(account); account.Balance -= transacton.Amount; db.Accounts.Update(account); db.Transactions.Add(transacton); } else { var payer = PayerInfo(); var account = PayerAccont(payer); var transacton = Transaction(account); db.Users.Add(payer); db.Accounts.Add(account); db.Transactions.Add(transacton); } if (db.Accounts.Any(a => a.IBAN == tbxIBANRecipient.Text)) { var account = db.Accounts.Where(a => a.IBAN == tbxIBANRecipient.Text).SingleOrDefault(); var transacton = Transaction(account); account.Balance += transacton.Amount; transacton.IsPaying = false; db.Accounts.Update(account); db.Transactions.Add(transacton); } else { var recipient = RecipientInfo(); var account = RecipientAccount(recipient); var transacton = Transaction(account); db.Users.Add(recipient); db.Accounts.Add(account); db.Transactions.Add(transacton); } db.SaveChanges(); } }
private void searchByIBAN() { using (var db = new PaymentSlipContext()) { var account = db.Accounts.Where(a => a.IBAN == tbxSearch.Text).SingleOrDefault(); var transaction = db.Transactions.Where(t => t.Account == account).ToList(); if (account == null) { MessageBox.Show("Krivi IBAN"); } double sum = 0.0; foreach (var trans in transaction) { if (trans.IsPaying) { sum += trans.Amount; } } MessageBox.Show("IBAN: " + account.IBAN + "\n" + "Placene transakcije: " + sum.ToString()); } }