private bool Update(string email) { bool isSuccess = false; int rowsAffected = 0; int signInCount = 0; DataTable datTable = GetUser(email); if (datTable != null && datTable.Rows.Count > 0) { var distinctRows = (from DataRow dRow in datTable.Rows where dRow.Field<string>("email") == email select new { column1 = dRow["sign_in_count"] }).Distinct(); if (distinctRows != null) { foreach (var row in distinctRows) { signInCount = Convert.ToInt32(row.column1.ToString()); signInCount++; break; } } StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE Users "); updateQuery.Append("SET "); updateQuery.Append("sign_in_count = @sign_in_count "); updateQuery.Append("WHERE "); updateQuery.Append("email = @email;"); using (SQLiteCommand commandSQLite = new SQLiteCommand(updateQuery.ToString())) { commandSQLite.Parameters.AddWithValue("@sign_in_count", signInCount); commandSQLite.Parameters.AddWithValue("@email", email); DataAccessLayer dataAccessObject = new DataAccessLayer(); rowsAffected = dataAccessObject.Execute(commandSQLite); } } if (rowsAffected > 0) { isSuccess = true; } return isSuccess; }
private bool Update(int orderId, string state, string updatedAt) { bool isSuccess = false; int rowsAffected = 0; StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE orders "); updateQuery.Append("SET "); updateQuery.Append("state = @state, "); updateQuery.Append("updated_at = @updated_at "); updateQuery.Append("WHERE "); updateQuery.Append("id = @id;"); using (SQLiteCommand commandSQLite = new SQLiteCommand(updateQuery.ToString())) { commandSQLite.Parameters.AddWithValue("@state", state); commandSQLite.Parameters.AddWithValue("@updated_at", updatedAt); commandSQLite.Parameters.AddWithValue("@id", orderId); DataAccessLayer dataAccessObject = new DataAccessLayer(); rowsAffected = dataAccessObject.Execute(commandSQLite); } if (rowsAffected > 0) { isSuccess = true; } return isSuccess; }
private bool Insert(string email, string password, string passwordConfirmation, string creditCardType, string creditCardNumber, string creditCardCVV2, string creditCardExpireMonth, string creditCardExpireYear) { bool isSuccess = false; int rowsAffected = 0; var encryptedPassword = Secure.Encrypt(password); var signInCount = 1; var dateTimeNow = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.FFFFF"); var currentSignInAt = dateTimeNow; var lastSignInAt = currentSignInAt; // Set first (current) signed in IP Address var signInIPAddress = string.Empty; var currentSignInIP = signInIPAddress; var lastSignInIP = signInIPAddress; var createdAt = dateTimeNow; var updatedAt = createdAt; CreditCard credCard = CreateCreditCard(creditCardType, creditCardNumber, creditCardCVV2, creditCardExpireMonth, creditCardExpireYear); var creditCardId = credCard.id; var creditCardDescription = credCard.number; StringBuilder insertQuery = new StringBuilder(); insertQuery.Append("INSERT INTO users"); insertQuery.Append("("); insertQuery.Append("email, "); insertQuery.Append("encrypted_password, "); insertQuery.Append("sign_in_count, "); insertQuery.Append("current_sign_in_at,"); insertQuery.Append("last_sign_in_at, "); insertQuery.Append("current_sign_in_ip, "); insertQuery.Append("last_sign_in_ip, "); insertQuery.Append("created_at, "); insertQuery.Append("updated_at, "); insertQuery.Append("credit_card_id, "); insertQuery.Append("credit_card_description "); insertQuery.Append(") "); insertQuery.Append("VALUES "); insertQuery.Append("("); insertQuery.Append("@email, "); insertQuery.Append("@encrypted_password, "); insertQuery.Append("@sign_in_count, "); insertQuery.Append("@current_sign_in_at,"); insertQuery.Append("@last_sign_in_at, "); insertQuery.Append("@current_sign_in_ip, "); insertQuery.Append("@last_sign_in_ip, "); insertQuery.Append("@created_at, "); insertQuery.Append("@updated_at, "); insertQuery.Append("@credit_card_id, "); insertQuery.Append("@credit_card_description "); insertQuery.Append(");"); using (SQLiteCommand commandSQLite = new SQLiteCommand(insertQuery.ToString())) { commandSQLite.Parameters.AddWithValue("@email", email); commandSQLite.Parameters.AddWithValue("@encrypted_password", encryptedPassword); commandSQLite.Parameters.AddWithValue("@sign_in_count", signInCount); commandSQLite.Parameters.AddWithValue("@current_sign_in_at", currentSignInAt); commandSQLite.Parameters.AddWithValue("@last_sign_in_at", lastSignInAt); commandSQLite.Parameters.AddWithValue("@current_sign_in_ip", currentSignInIP); commandSQLite.Parameters.AddWithValue("@last_sign_in_ip", lastSignInIP); commandSQLite.Parameters.AddWithValue("@created_at", createdAt); commandSQLite.Parameters.AddWithValue("@updated_at", updatedAt); commandSQLite.Parameters.AddWithValue("@credit_card_id", creditCardId); commandSQLite.Parameters.AddWithValue("@credit_card_description", creditCardDescription); DataAccessLayer dataAccessObject = new DataAccessLayer(); rowsAffected = dataAccessObject.Execute(commandSQLite); } if (rowsAffected > 0) { isSuccess = true; } return isSuccess; }
private bool Insert(int userId, string createdAt, string updatedAt) { bool isSuccess = false; int rowsAffected = 0; StringBuilder insertQuery = new StringBuilder(); insertQuery.Append("INSERT INTO orders"); insertQuery.Append("("); insertQuery.Append("user_id, "); insertQuery.Append("created_at, "); insertQuery.Append("updated_at "); insertQuery.Append(") "); insertQuery.Append("VALUES "); insertQuery.Append("("); insertQuery.Append("@user_id, "); insertQuery.Append("@created_at, "); insertQuery.Append("@updated_at "); insertQuery.Append(");"); using (SQLiteCommand commandSQLite = new SQLiteCommand(insertQuery.ToString())) { commandSQLite.Parameters.AddWithValue("@user_id", userId); commandSQLite.Parameters.AddWithValue("@created_at", createdAt); commandSQLite.Parameters.AddWithValue("@updated_at", updatedAt); DataAccessLayer dataAccessObject = new DataAccessLayer(); rowsAffected = dataAccessObject.Execute(commandSQLite); } if (rowsAffected > 0) { isSuccess = true; } return isSuccess; }
private bool Update(string email, string newPassword, string confirmNewPassword, string newCreditCardType, string newCreditCardNumber, string newCreditCardCVV2, string newCreditCardExpireMonth, string newCreditCardExpireYear) { bool isSuccess = false; int rowsAffected = 0; var encryptedNewPassword = Secure.Encrypt(newPassword); var signInCount = 0; var dateTimeNow = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss.FFFFF"); var currentSignInAt = dateTimeNow; // Set last signed in IP Address from database var lastSignInAt = string.Empty; // Set first signed in IP Address from database var signInIPAddress = string.Empty; // Set current signed in IP Address var currentSignInIP = string.Empty; // Set last signed in IP Address from database var lastSignInIP = string.Empty; var createdAt = string.Empty; var updatedAt = dateTimeNow; DataTable datTable = GetUser(email); if (datTable != null && datTable.Rows.Count > 0) { var distinctRows = (from DataRow dRow in datTable.Rows where dRow.Field<string>("email") == email select new { column1 = dRow["sign_in_count"], column2 = dRow["last_sign_in_at"], column3 = dRow["last_sign_in_ip"], column4 = dRow["created_at"] }).Distinct(); if (distinctRows != null) { foreach (var row in distinctRows) { signInCount = Convert.ToInt32(row.column1.ToString()); signInCount++; DateTime lastSignInAtDateTime = Convert.ToDateTime(row.column2); lastSignInAt = lastSignInAtDateTime.ToString("yyyy-MM-dd hh:mm:ss.FFFFF"); lastSignInIP = Convert.ToString(row.column3); DateTime createdAtDateTime = Convert.ToDateTime(row.column4); createdAt = createdAtDateTime.ToString("yyyy-MM-dd hh:mm:ss.FFFFF"); break; } } CreditCard credCard = CreateCreditCard(newCreditCardType, newCreditCardNumber, newCreditCardCVV2, newCreditCardExpireMonth, newCreditCardExpireYear); var creditCardId = credCard.id; var creditCardDescription = credCard.number; StringBuilder updateQuery = new StringBuilder(); updateQuery.Append("UPDATE Users "); updateQuery.Append("SET "); updateQuery.Append("encrypted_password = @encrypted_password, "); updateQuery.Append("sign_in_count = @sign_in_count, "); updateQuery.Append("current_sign_in_at = @current_sign_in_at, "); updateQuery.Append("last_sign_in_at = @last_sign_in_at, "); updateQuery.Append("current_sign_in_ip = @current_sign_in_ip, "); updateQuery.Append("last_sign_in_ip = @last_sign_in_ip, "); updateQuery.Append("created_at = @created_at, "); updateQuery.Append("credit_card_id = @credit_card_id, "); updateQuery.Append("credit_card_description = @credit_card_description "); updateQuery.Append("WHERE "); updateQuery.Append("email = @email;"); using (SQLiteCommand commandSQLite = new SQLiteCommand(updateQuery.ToString())) { commandSQLite.Parameters.AddWithValue("@email", email); commandSQLite.Parameters.AddWithValue("@encrypted_password", encryptedNewPassword); commandSQLite.Parameters.AddWithValue("@sign_in_count", signInCount); commandSQLite.Parameters.AddWithValue("@current_sign_in_at", currentSignInAt); commandSQLite.Parameters.AddWithValue("@last_sign_in_at", lastSignInAt); commandSQLite.Parameters.AddWithValue("@current_sign_in_ip", currentSignInIP); commandSQLite.Parameters.AddWithValue("@last_sign_in_ip", lastSignInIP); commandSQLite.Parameters.AddWithValue("@created_at", createdAt); commandSQLite.Parameters.AddWithValue("@updated_at", updatedAt); commandSQLite.Parameters.AddWithValue("@credit_card_id", creditCardId); commandSQLite.Parameters.AddWithValue("@credit_card_description", creditCardDescription); DataAccessLayer dataAccessObject = new DataAccessLayer(); rowsAffected = dataAccessObject.Execute(commandSQLite); } } if (rowsAffected > 0) { isSuccess = true; } return isSuccess; }