private static KeyValuePair <NpgsqlCommand, string> getParameter(ClientModelSearch clientModel) { ToastrUtilities toastrUtilities = new ToastrUtilities(); string txtClientId = string.Empty, txtClientEmail = string.Empty, txtClientName = string.Empty, txtPhoneNumber = string.Empty; txtClientId = clientModel.Id; txtClientEmail = clientModel.Email; txtClientName = clientModel.First_name; txtPhoneNumber = clientModel.Phone_number; string query = string.Empty; NpgsqlCommand command = new NpgsqlCommand(); if (!string.IsNullOrEmpty(txtClientId)) { try { command.Parameters.AddWithValue("@ClientId", Convert.ToInt32(txtClientId)); query += " AND id = @ClientId"; } catch { toastrUtilities.SessionPush("toast", new KeyValuePair <string, string>("error", "Invalid Client ID")); } } if (!string.IsNullOrEmpty(txtClientEmail)) { command.Parameters.AddWithValue("@ClientEmail", txtClientEmail); query += " AND email = @ClientEmail"; } if (!string.IsNullOrEmpty(txtClientName)) { command.Parameters.AddWithValue("@ClientName", txtClientName); query += " AND first_name::text || ' ' || last_name::text = @ClientName"; } if (!string.IsNullOrEmpty(txtPhoneNumber)) { command.Parameters.AddWithValue("@PhoneNumber", txtPhoneNumber); query += " AND phone_prefix::text || phone_number::text = @PhoneNumber"; } KeyValuePair <NpgsqlCommand, string> pair = new KeyValuePair <NpgsqlCommand, string>(command, query); return(pair); }
public static AjaxResponse ChangeStatus(string id, string selectedStatus, string ref_hash) { string DecryptedId = Classes.encryption.Decrypt(id); using (NpgsqlConnection conn = Classes.DB.InstBTCDB("instbtc")) { //Update Status bool updateResult = WithdrawalUtilities.UpdateCreditedStatus(conn, DecryptedId, selectedStatus, ref_hash); if (updateResult) { if (selectedStatus == "Approved") { WithdrawalUtilities.UpdateUsdValueAmount(conn, DecryptedId); var withdrawalData = WithdrawalUtilities.GetWithdrawal(conn, DecryptedId); if (withdrawalData.TransactionId == -1 && withdrawalData.Status == "Approved") { var result = InsertTransaction(conn, DecryptedId, createTransferRecord: false); if (result.ToString() != "Internal Error" && !string.IsNullOrEmpty(result.ToString())) { var updateWithdrawalTransaction = WithdrawalUtilities.UpdateTransactionId(conn, DecryptedId, Convert.ToInt32(result)); ToastrUtilities toastrUtilities = new ToastrUtilities(); if (updateWithdrawalTransaction) { toastrUtilities.SessionPush("toast", new KeyValuePair <string, string>("success", "Successfully Updated Status")); } else { toastrUtilities.SessionPush("toast", new KeyValuePair <string, string>("error", "Encountered Error Update Status")); } } } } } //Set Response AjaxResponse res = new AjaxResponse() { Success = updateResult, DocumentId = Convert.ToInt32(DecryptedId) }; return(res); } }
private static KeyValuePair <NpgsqlCommand, string> getParameter(WithdrawalSearchModel sessionSearchModel) { ToastrUtilities toastrUtilities = new ToastrUtilities(); string txtStatus = sessionSearchModel?.Status ?? string.Empty; string txtClientId = sessionSearchModel?.ClientModel?.Id ?? string.Empty; string txtClientEmail = sessionSearchModel?.ClientModel?.Email ?? string.Empty; string txtClientName = sessionSearchModel?.ClientName ?? string.Empty; string txtWalletId = sessionSearchModel?.WalletId ?? string.Empty; string txtDocumentId = sessionSearchModel?.DocumentId ?? string.Empty; string txtCreatedDate = sessionSearchModel?.CreatedDate ?? string.Empty; string txtDocStatus = sessionSearchModel?.DocumentStatus ?? string.Empty; string txtHash = sessionSearchModel?.refference_hash ?? string.Empty; string query = string.Empty; NpgsqlCommand command = new NpgsqlCommand(); if (!string.IsNullOrEmpty(txtStatus)) { command.Parameters.AddWithValue("@Status", txtStatus); query += " AND w.credited_status = @Status"; } if (!string.IsNullOrEmpty(txtHash)) { command.Parameters.AddWithValue("@refference_hash", txtHash); query += " AND w.refference_hash = @refference_hash"; } if (!string.IsNullOrEmpty(txtDocStatus)) { if (int.TryParse(txtDocStatus, out int ds)) { command.Parameters.AddWithValue("@docstatus", ds); query += " AND w.document_status = @docstatus"; } } if (!string.IsNullOrEmpty(txtClientId)) { if (int.TryParse(txtClientId, out int cid)) { command.Parameters.AddWithValue("@ClientId", cid); query += " AND w.user_id = @ClientId"; } else { toastrUtilities.SessionPush("toast", new KeyValuePair <string, string>("error", "Invalid Client ID")); } } if (!string.IsNullOrEmpty(txtClientEmail)) { command.Parameters.AddWithValue("@ClientEmail", txtClientEmail); query += " AND c.email = @ClientEmail"; } if (!string.IsNullOrEmpty(txtClientName)) { command.Parameters.AddWithValue("@ClientName", txtClientName); query += " AND w.client_name = @ClientName"; } if (!string.IsNullOrEmpty(txtWalletId)) { command.Parameters.AddWithValue("@WalletId", txtWalletId); query += " AND w.wallet_id = @WalletId"; } if (!string.IsNullOrEmpty(txtDocumentId)) { if (int.TryParse(txtDocumentId, out int did)) { command.Parameters.AddWithValue("@DocumentId", did); query += " AND w.document_id = @DocumentId"; } else { toastrUtilities.SessionPush("toast", new KeyValuePair <string, string>("error", "Invalid Document ID")); } } if (!string.IsNullOrEmpty(txtCreatedDate)) { if (DateTime.TryParse(txtCreatedDate, out DateTime cd)) { command.Parameters.AddWithValue("@CreatedDate", cd); query += " AND w.created_date::date = @CreatedDate"; } else { toastrUtilities.SessionPush("toast", new KeyValuePair <string, string>("error", "Invalid Date")); } } KeyValuePair <NpgsqlCommand, string> pair = new KeyValuePair <NpgsqlCommand, string>(command, query); return(pair); }