public AccountType GetAccount(AccountType obj) { AccountType account; using (EFAccountDB ConnectionContext = new EFAccountDB(builder.ConnectionString)) { account = convertToAccountType(ConnectionContext.Accounts.Find(convertToAccount(obj).Id)); } return(account); }
public AccountType GetAccount(string AccountLogin, string AccountPassword) { Account account; using (EFAccountDB ConnectionContext = new EFAccountDB(builder.ConnectionString)) { account = ConnectionContext.Accounts.Where(a => a.AccountLogin == AccountLogin).Where(a => a.AccountPassword == AccountPassword).FirstOrDefault(); } AccountType accountType = convertToAccountType(account); return(accountType); }
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); }