private bool Insert()
        {
            bool          isSuccess             = false;
            int           rowsAffacted          = 0;
            var           email                 = TextBoxEmail.Text.Trim();
            var           password              = TextBoxPassword.Text.Trim();
            var           passwordConfirmation  = TextBoxConfirmPassword.Text.Trim();
            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          = dateTimeNow;
            var           signInIPAddress       = ConfigManager.Instance.GetProperty("IPAddress");
            var           currentSignInIP       = signInIPAddress;
            var           lastSignInIP          = signInIPAddress;
            var           createdAt             = dateTimeNow;
            var           updatedAt             = dateTimeNow;
            CreditCard    credCard              = CreateCreditCard();
            var           creditCardID          = credCard.id;
            var           creditCardDescription = credCard.number;
            StringBuilder sqliteQueryInsert     = new StringBuilder();

            sqliteQueryInsert.Append("INSERT INTO users");
            sqliteQueryInsert.Append("(");
            sqliteQueryInsert.Append("email, ");
            sqliteQueryInsert.Append("encrypted_password, ");
            sqliteQueryInsert.Append("sign_in_count, ");
            sqliteQueryInsert.Append("current_sign_in_at,");
            sqliteQueryInsert.Append("last_sign_in_at, ");
            sqliteQueryInsert.Append("current_sign_in_ip, ");
            sqliteQueryInsert.Append("last_sign_in_ip, ");
            sqliteQueryInsert.Append("created_at, ");
            sqliteQueryInsert.Append("updated_at, ");
            sqliteQueryInsert.Append("credit_card_id, ");
            sqliteQueryInsert.Append("credit_card_description ");
            sqliteQueryInsert.Append(") ");
            sqliteQueryInsert.Append("VALUES ");
            sqliteQueryInsert.Append("(");
            sqliteQueryInsert.Append("@email, ");
            sqliteQueryInsert.Append("@encrypted_password, ");
            sqliteQueryInsert.Append("@sign_in_count, ");
            sqliteQueryInsert.Append("@current_sign_in_at,");
            sqliteQueryInsert.Append("@last_sign_in_at, ");
            sqliteQueryInsert.Append("@current_sign_in_ip, ");
            sqliteQueryInsert.Append("@last_sign_in_ip, ");
            sqliteQueryInsert.Append("@created_at, ");
            sqliteQueryInsert.Append("@updated_at, ");
            sqliteQueryInsert.Append("@credit_card_id, ");
            sqliteQueryInsert.Append("@credit_card_description ");
            sqliteQueryInsert.Append(")");
            SQLiteDataAdapter sqliteDataAdapterInsert = new SQLiteDataAdapter();

            sqliteDataAdapterInsert.InsertCommand = new SQLiteCommand();
            sqliteDataAdapterInsert.InsertCommand.Parameters.AddWithValue("@email", email);
            sqliteDataAdapterInsert.InsertCommand.Parameters.AddWithValue("@encrypted_password", encryptedPassword);
            sqliteDataAdapterInsert.InsertCommand.Parameters.AddWithValue("@sign_in_count", signInCount);
            sqliteDataAdapterInsert.InsertCommand.Parameters.AddWithValue("@current_sign_in_at", currentSignInAt);
            sqliteDataAdapterInsert.InsertCommand.Parameters.AddWithValue("@last_sign_in_at", lastSignInAt);
            sqliteDataAdapterInsert.InsertCommand.Parameters.AddWithValue("@current_sign_in_ip", currentSignInIP);
            sqliteDataAdapterInsert.InsertCommand.Parameters.AddWithValue("@last_sign_in_ip", lastSignInIP);
            sqliteDataAdapterInsert.InsertCommand.Parameters.AddWithValue("@created_at", createdAt);
            sqliteDataAdapterInsert.InsertCommand.Parameters.AddWithValue("@updated_at", updatedAt);
            sqliteDataAdapterInsert.InsertCommand.Parameters.AddWithValue("@credit_card_id", creditCardID);
            sqliteDataAdapterInsert.InsertCommand.Parameters.AddWithValue("@credit_card_description", creditCardDescription);
            dataAccessObject = new DataAccessLayer();
            rowsAffacted     = dataAccessObject.Insert(sqliteQueryInsert.ToString(), sqliteDataAdapterInsert);
            if (rowsAffacted > 0)
            {
                isSuccess = true;
            }
            return(isSuccess);
        }
示例#2
0
        private bool Update(string email)
        {
            bool isSuccess = false;

            int rowsAffacted         = 0;
            var newPassword          = TextBoxNewPassword.Text.Trim();
            var confirmNewPassword   = TextBoxConfirmNewPassword.Text.Trim();
            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"] };
                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();
                var           creditCardID          = credCard.id;
                var           creditCardDescription = credCard.number;
                StringBuilder sqliteQueryUpdate     = new StringBuilder();
                sqliteQueryUpdate.Append("UPDATE Users ");
                sqliteQueryUpdate.Append("SET ");
                sqliteQueryUpdate.Append("encrypted_password = @encrypted_password, ");
                sqliteQueryUpdate.Append("sign_in_count = @sign_in_count, ");
                sqliteQueryUpdate.Append("current_sign_in_at = @current_sign_in_at, ");
                sqliteQueryUpdate.Append("last_sign_in_at = @last_sign_in_at, ");
                sqliteQueryUpdate.Append("current_sign_in_ip = @current_sign_in_ip, ");
                sqliteQueryUpdate.Append("last_sign_in_ip = @last_sign_in_ip, ");
                sqliteQueryUpdate.Append("created_at = @created_at, ");
                sqliteQueryUpdate.Append("credit_card_id = @credit_card_id, ");
                sqliteQueryUpdate.Append("credit_card_description = @credit_card_description ");
                sqliteQueryUpdate.Append("WHERE ");
                sqliteQueryUpdate.Append("email = @email");
                SQLiteDataAdapter sqliteDataAdapterUpdate = new SQLiteDataAdapter();
                sqliteDataAdapterUpdate.UpdateCommand = new SQLiteCommand();
                sqliteDataAdapterUpdate.UpdateCommand.Parameters.AddWithValue("@email", email);
                sqliteDataAdapterUpdate.UpdateCommand.Parameters.AddWithValue("@encrypted_password", encryptedNewPassword);
                sqliteDataAdapterUpdate.UpdateCommand.Parameters.AddWithValue("@sign_in_count", signInCount);
                sqliteDataAdapterUpdate.UpdateCommand.Parameters.AddWithValue("@current_sign_in_at", currentSignInAt);
                sqliteDataAdapterUpdate.UpdateCommand.Parameters.AddWithValue("@last_sign_in_at", lastSignInAt);
                sqliteDataAdapterUpdate.UpdateCommand.Parameters.AddWithValue("@current_sign_in_ip", currentSignInIP);
                sqliteDataAdapterUpdate.UpdateCommand.Parameters.AddWithValue("@last_sign_in_ip", lastSignInIP);
                sqliteDataAdapterUpdate.UpdateCommand.Parameters.AddWithValue("@created_at", createdAt);
                sqliteDataAdapterUpdate.UpdateCommand.Parameters.AddWithValue("@updated_at", updatedAt);
                sqliteDataAdapterUpdate.UpdateCommand.Parameters.AddWithValue("@credit_card_id", creditCardID);
                sqliteDataAdapterUpdate.UpdateCommand.Parameters.AddWithValue("@credit_card_description", creditCardDescription);
                dataAccessObject = new DataAccessLayer();
                rowsAffacted     = dataAccessObject.Update(sqliteQueryUpdate.ToString(), sqliteDataAdapterUpdate);
            }
            if (rowsAffacted > 0)
            {
                isSuccess = true;
            }
            return(isSuccess);
        }