public async Task <ActionResult> UpdateWithdrawalTxId(UpdateWithdrawalTxModel model)
        {
            if (!ModelState.IsValid)
            {
                return(CloseModalError("Invalid input."));
            }

            var result = await ReprocessingWriter.UpdateWithrawalTransactionId(User.Identity.GetUserId(), model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(CloseModalError(result.Message));
            }

            return(CloseModalSuccess(result.Message));
        }
        public async Task <IWriterResult> UpdateWithrawalTransactionId(string adminUserId, UpdateWithdrawalTxModel model)
        {
            Withdraw existing = null;

            using (var context = ExchangeDataContextFactory.CreateReadOnlyContext())
            {
                existing = await context.Withdraw.FirstOrDefaultNoLockAsync(x => x.Id.Equals(model.Id)).ConfigureAwait(false);

                if (existing == null)
                {
                    return(new WriterResult(false, "No Withdrawal found to update."));
                }

                if (model.Status != Cryptopia.Enums.WithdrawStatus.Processing)
                {
                    return(new WriterResult(false, "Withdrawal in incorrect state to update."));
                }

                if (!model.Address.Equals(existing.Address))
                {
                    return(new WriterResult(false, "Original and updated withdrawal addresses are different."));
                }

                if (!model.Amount.Equals(existing.Amount))
                {
                    return(new WriterResult(false, "Original and updated withdrawal amounts are different."));
                }
            }

            // post the request to the approval queue
            using (var approvalContext = DataContextFactory.CreateContext())
            {
                try
                {
                    string withdrawalId     = $"{model.Id}";
                    string withdrawalUserId = $"{existing.UserId}";
                    var    approval         = await approvalContext.ApprovalQueue.FirstOrDefaultNoLockAsync(a => a.DataUserId == withdrawalUserId &&
                                                                                                            a.Type == ApprovalQueueType.WithdrawalReprocessing &&
                                                                                                            a.Status == ApprovalQueueStatus.Pending &&
                                                                                                            a.Data == withdrawalId);

                    if (approval != null)
                    {
                        return(new WriterResult(false, "Already awaiting approval."));
                    }

                    approval = new Entity.ApprovalQueue
                    {
                        DataUserId    = $"{existing.UserId}",
                        RequestUserId = adminUserId,
                        Type          = ApprovalQueueType.WithdrawalReprocessing,
                        Status        = ApprovalQueueStatus.Pending,
                        Created       = DateTime.UtcNow,
                        Data          = JsonConvert.SerializeObject(new ReprocessingApprovalDataModel {
                            WithdrawalId = $"{model.Id}", TxId = model.TxId
                        })
                    };

                    approvalContext.ApprovalQueue.Add(approval);
                    await approvalContext.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    return(new WriterResult(false, "Failed to add request to Approval Queue."));
                }

                return(new WriterResult(true, $"Successfully added Withdrawal: {existing.Id} to Approval Queue."));
            }
        }