private static async Task <BankTransactionCategory> GetOrCreateNewCategory(ClubTreasurerContext context, GeorgeTransaction transaction) { var category = await SearchByMultipleKeyword(context, transaction.Reference); if (category != null) { return(category); } else { category = await context.BankTransactionCategorys.FirstOrDefaultAsync(a => a.Name == "Undefined"); } if (category != null) { return(category); } else { category = new BankTransactionCategory() { Name = "Undefined", }; context.BankTransactionCategorys.Add(category); await context.SaveChangesAsync(); } return(category); }
private static async Task <BankAccount> GetOrCreateNewAccount(ClubTreasurerContext context, GeorgeTransaction transaction) { BankAccount account; if (transaction.PartnerAccount?.Iban == null) { //cash payment account = await GetOwnBankAccount(context, "AT722050303300000928"); if (account != null) { return(account); } } account = await context.BankAccounts.FirstOrDefaultAsync(a => a.ID == transaction.PartnerAccount.Iban); if (account != null) { return(account); } else { account = new BankAccount { ID = transaction.PartnerAccount.Iban, Name = transaction.PartnerName }; context.BankAccounts.Add(account); try { await context.SaveChangesAsync(); } catch (Exception ex) { var test = ex; } //try to assign it to a person var person = context.Persons.Where(p => p.FullName == transaction.PartnerName || p.FullNameReverse == transaction.PartnerName).FirstOrDefault(); if (person != null) { context.Attach(person).State = EntityState.Modified; if (person.BankAccounts == null) { person.BankAccounts = new List <BankAccount> { account }; await context.SaveChangesAsync(); } else { person.BankAccounts.Add(account); } } return(account); } }
public static List <GeorgeTransaction> ImportFromJson(string json) { return(GeorgeTransaction.FromJson(json)); }