public void UpdateAccount(AccountType obj) { Account account = convertToAccount(obj); Account account_from_db; using (EFAccountDB ConnectionContext = new EFAccountDB(builder.ConnectionString)) { account_from_db = ConnectionContext.Accounts.Find(account.Id); if (account_from_db != null) { ConnectionContext.Entry(account_from_db).CurrentValues.SetValues(account); ConnectionContext.SaveChanges(); } } }
public int InsertAccount(AccountType obj) { Account account = convertToAccount(obj); using (EFAccountDB ConnectionContext = new EFAccountDB(builder.ConnectionString)) { try { ConnectionContext.Accounts.Add(account); ConnectionContext.SaveChanges(); } catch (SqlException e) { if (e.Message.Contains("duplicate")) { return(-1); } } } Console.WriteLine("\nAdded Account: " + account.ToString()); return(GetAccount(account.AccountLogin, account.AccountPassword).AccountID); }