public bool ConfirmTransfer(Guid userId, Guid transactionId, string otp)
        {
            var res = false;

            using (var sessionTask = _MongoDBClient.StartSessionAsync())
            {
                var session = sessionTask.Result;
                session.StartTransaction();
                try
                {
                    // Get detail user
                    var userDetail = _UserCollection.GetById(userId);

                    if (userDetail != null)
                    {
                        // Get Get chi tiết giao dịch
                        var transaction = _TransactionCollection.GetById(transactionId);
                        if (transaction != null)
                        {
                            // Check OTP
                            if (transaction.Otp == otp)
                            {
                                // Check hết hạn
                                if (transaction.ExpireTime >= DateTime.Now)
                                {
                                    // Get chi tiết chuyển tiền
                                    var transfer = _TransferCollection.GetById(transaction.ReferenceId);
                                    // Check user hiện tại có tạo yêu cầu chuyển tiền
                                    if (transfer != null &&
                                        transfer.SourceLinkingBankId == Guid.Empty &&
                                        transfer.SourceAccountNumber == userDetail.AccountNumber)
                                    {
                                        // Tru so du
                                        userDetail.CheckingAccount.AccountBalance -= transfer.Money;
                                        transfer.Fee = _Context.TransactionCost(transfer.Money);

                                        // Tru phi
                                        if (transfer.IsSenderPay)
                                        {
                                            userDetail.CheckingAccount.AccountBalance -= transfer.Fee;
                                        }

                                        if (userDetail.CheckingAccount.AccountBalance >= 0)
                                        {
                                            // Luu thong tin nguoi gui
                                            var payOut = _UserCollection.UpdateCheckingAccount(new UserFilter()
                                            {
                                                Id = userId
                                            }, userDetail.CheckingAccount);

                                            if (payOut > 0)
                                            {
                                                // Cong tien nguoi nhan
                                                var success = false;
                                                if (transfer.DestinationLinkingBankId == Guid.Empty)
                                                {
                                                    // noi bo
                                                    var detailRecepients = _UserCollection.Get(new UserFilter()
                                                    {
                                                        AccountNumber = transfer.DestinationAccountNumber
                                                    });
                                                    if (detailRecepients.Any())
                                                    {
                                                        var detailRecepient = detailRecepients.FirstOrDefault();
                                                        detailRecepient.CheckingAccount.AccountBalance += transfer.Money;
                                                        // Tru phi
                                                        if (!transfer.IsSenderPay)
                                                        {
                                                            detailRecepient.CheckingAccount.AccountBalance -= transfer.Fee;
                                                        }

                                                        payOut = _UserCollection.UpdateCheckingAccount(new UserFilter()
                                                        {
                                                            Id = detailRecepient.Id
                                                        }, detailRecepient.CheckingAccount);

                                                        if (payOut > 0)
                                                        {
                                                            success = true;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        _Setting.Message.SetMessage("Không tìm thấy thông tin người nhận!");
                                                    }
                                                }
                                                else
                                                {
                                                    // lien ngan hang
                                                    // TODO
                                                    // Khuê
                                                    IExternalBanking externalBanking = null;
                                                    if (transfer.DestinationLinkingBankId == Guid.Parse("8df09f0a-fd6d-42b9-804c-575183dadaf3"))
                                                    {
                                                        externalBanking = new ExternalBanking_BKTBank(_Encrypt, _Setting);
                                                        externalBanking.SetPartnerCode();
                                                    }

                                                    var result = externalBanking.PayIn(transfer.SourceAccountNumber, transfer.DestinationAccountNumber, transfer.Money, transfer.Description);

                                                    success = result;
                                                }

                                                if (success)
                                                {
                                                    // Update trạng thái chuyển tiền
                                                    transfer.IsConfirmed = true;
                                                    var updateTransfer = _TransferCollection.Replace(transfer);
                                                    if (updateTransfer > 0)
                                                    {
                                                        // Update trạng thái giao dịch
                                                        transaction.ConfirmTime = DateTime.Now;
                                                        var updateTransaction = _TransactionCollection.Replace(transaction);
                                                        if (updateTransaction > 0)
                                                        {
                                                            // Send mail
                                                            // TODO
                                                            res = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            _Setting.Message.SetMessage("Số dư không đủ!");
                                        }
                                    }
                                    else
                                    {
                                        _Setting.Message.SetMessage("Không tìm thấy thông tin chuyển tiền!");
                                    }
                                }
                                else
                                {
                                    _Setting.Message.SetMessage("Phiên giao dịch hết hạn!");
                                }
                            }
                            else
                            {
                                _Setting.Message.SetMessage("Sai mã OTP!");
                            }
                        }
                        else
                        {
                            _Setting.Message.SetMessage("Không tìm thấy thông tin giao dịch!");
                        }
                    }
                    else
                    {
                        _Setting.Message.SetMessage("Không tìm thấy thông tin người gửi yêu cầu!");
                    }

                    if (res)
                    {
                        session.CommitTransactionAsync();
                    }
                    else
                    {
                        session.AbortTransactionAsync();
                    }
                }
                catch (Exception)
                {
                    session.AbortTransactionAsync().Wait();
                    throw;
                }
            }

            return(res);
        }
        public bool ConfirmDeptReminder(Guid userId, Guid transactionId, string otp)
        {
            var res = false;

            using (var sessionTask = _MongoDBClient.StartSessionAsync())
            {
                var session = sessionTask.Result;
                session.StartTransaction();
                try
                {
                    // Get detail user
                    var userDetail = _UserCollection.GetById(userId);

                    if (userDetail != null)
                    {
                        // Get chi tiết giao dịch
                        var transaction = _TransactionCollection.GetById(transactionId);
                        if (transaction != null)
                        {
                            // Check mã OTP
                            if (transaction.Otp == otp)
                            {
                                // Kiểm tra hết hạn
                                if (transaction.ExpireTime >= DateTime.Now)
                                {
                                    // Get chi tiết nhăc nợ
                                    var dept = _DeptReminderCollection.GetById(transaction.ReferenceId);
                                    if (dept != null)
                                    {
                                        // Trừ số dư
                                        userDetail.CheckingAccount.AccountBalance -= dept.Money;
                                        var fee = _Context.TransactionCost(dept.Money);

                                        // Trừ phí
                                        userDetail.CheckingAccount.AccountBalance -= fee;

                                        if (userDetail.CheckingAccount.AccountBalance >= 0)
                                        {
                                            // Update thông tin người trả nợ
                                            var payOut = _UserCollection.UpdateCheckingAccount(new UserFilter()
                                            {
                                                Id = userId
                                            }, userDetail.CheckingAccount);

                                            if (payOut > 0)
                                            {
                                                // Cộng tiền người nhận
                                                var detailRecepient = _UserCollection.GetById(dept.RequestorId);
                                                if (detailRecepient != null)
                                                {
                                                    detailRecepient.CheckingAccount.AccountBalance += dept.Money;

                                                    payOut = _UserCollection.UpdateCheckingAccount(new UserFilter()
                                                    {
                                                        Id = detailRecepient.Id
                                                    }, detailRecepient.CheckingAccount);

                                                    if (payOut > 0)
                                                    {
                                                        // Update trạng thái nhắc nợ
                                                        dept.IsPaid = true;
                                                        if (_DeptReminderCollection.Replace(dept) > 0)
                                                        {
                                                            // Update trang thai giao dich
                                                            transaction.ConfirmTime = DateTime.Now;
                                                            if (_TransactionCollection.Replace(transaction) > 0)
                                                            {
                                                                // Send mail
                                                                var sb = new StringBuilder();
                                                                sb.AppendFormat($"Dear {detailRecepient.Name},");
                                                                sb.AppendFormat("<br /><br /><b>Nhắc nợ của bạn đã được thanh toán.:</b>");
                                                                sb.AppendFormat($"<br /><br /><b>Mã: {dept.Code}</b>");
                                                                sb.AppendFormat($"<br /><br /><b>Người thanh toán: {userDetail.AccountNumber} - {userDetail.Name }</b>");
                                                                sb.AppendFormat($"<br /><br /><b>Vui lòng đăng nhập vào hệ thống để xem chi tiết.</b>");
                                                                sb.AppendFormat($"<br /><br /><b>Nếu yêu cầu không phải của bạn, vui lòng bỏ qua mail này.</b>");

                                                                if (_Context.SendMail("Thanh toán nhắc nợ", sb.ToString(), detailRecepient.Email, detailRecepient.Name))
                                                                {
                                                                    res = true;
                                                                }
                                                            }
                                                            else
                                                            {
                                                                _Setting.Message.SetMessage("Không thể cập nhật số liệu!");
                                                            }
                                                        }
                                                        else
                                                        {
                                                            _Setting.Message.SetMessage("Không thể cập nhật số liệu!");
                                                        }
                                                    }
                                                    else
                                                    {
                                                        _Setting.Message.SetMessage("Không thể cập nhật số liệu!");
                                                    }
                                                }
                                                else
                                                {
                                                    _Setting.Message.SetMessage("Không tìm thấy thông tin người nhận!");
                                                }
                                            }
                                            else
                                            {
                                                _Setting.Message.SetMessage("Không thể cập nhật số liệu!");
                                            }
                                        }
                                        else
                                        {
                                            _Setting.Message.SetMessage("Số dư không đủ!");
                                        }
                                    }
                                    else
                                    {
                                        _Setting.Message.SetMessage("Không tìm thấy thông tin nhắc nợ!");
                                    }
                                }
                                else
                                {
                                    _Setting.Message.SetMessage("Phiên giao dịch hết hạn!");
                                }
                            }
                            else
                            {
                                _Setting.Message.SetMessage("Sai mã OTP!");
                            }
                        }
                        else
                        {
                            _Setting.Message.SetMessage("Không tìm thấy thông tin giao dịch!");
                        }
                    }
                    else
                    {
                        _Setting.Message.SetMessage("Không tìm thấy thông tin người gửi yêu cầu!");
                    }

                    if (res)
                    {
                        session.CommitTransactionAsync();
                    }
                    else
                    {
                        session.AbortTransactionAsync();
                    }
                }
                catch (Exception ex)
                {
                    session.AbortTransactionAsync();
                    throw ex;
                }
            }

            return(res);
        }
        public bool ConfirmForgetting(Guid id, string email, string otp)
        {
            var res = false;

            var details = _UserCollection.Get(new UserFilter()
            {
                Email = email
            });

            if (details != null && details.Any())
            {
                var detail = details.FirstOrDefault();
                // Get chi tiết giao dịch
                var transactions = _TransactionCollection.GetMany(new TransactionFilter()
                {
                    Id = id, ReferenceId = detail.Id, Type = 2
                });
                if (transactions.Any())
                {
                    var transaction = transactions.FirstOrDefault();
                    // Check Otp
                    if (transaction.Otp == otp)
                    {
                        // Check hết hạn
                        var now = DateTime.Now;
                        if (now <= transaction.ExpireTime && now >= transaction.CreateTime)
                        {
                            // Update mật khẩu
                            using (var sessionTask = _MongoDBClient.StartSessionAsync())
                            {
                                var session = sessionTask.Result;
                                session.StartTransaction();
                                try
                                {
                                    // Create mật khẩu mới
                                    string pass = _Context.MakeOTP(8);

                                    if (_UserCollection.ChangePassword(new UserFilter()
                                    {
                                        Id = detail.Id
                                    }, Encrypting.Bcrypt(pass)) > 0)
                                    {
                                        // Update giao dịch
                                        transaction.ConfirmTime = DateTime.Now;

                                        if (_TransactionCollection.Replace(transaction) > 0)
                                        {
                                            // Send mail
                                            var sb = new StringBuilder();
                                            sb.AppendFormat($"Dear {detail.Name},");
                                            sb.AppendFormat("<br /><br /><b>Yêu cầu quên mật khẩu của bạn đã thực hiện thành công, mật khẩu mới của bạn là:</b>");
                                            sb.AppendFormat($"<br /><br /><b>{pass}</b>");
                                            sb.AppendFormat($"<br /><br /><b>Vui lòng đăng nhập vào hệ thống để kiểm tra.</b>");
                                            sb.AppendFormat($"<br /><br /><b>Nếu yêu cầu không phải của bạn, vui lòng bỏ qua mail này.</b>");

                                            if (_Context.SendMail("Yêu cầu quên mật khẩu", sb.ToString(), detail.Email, detail.Name))
                                            {
                                                res = true;
                                            }
                                            else
                                            {
                                                _Setting.Message.SetMessage("Gửi mail thất bại!");
                                            }
                                        }
                                        else
                                        {
                                            _Setting.Message.SetMessage("Không thể cập nhật thông tin giao dịch!");
                                        }
                                    }
                                    else
                                    {
                                        _Setting.Message.SetMessage("Không thể cập nhật thông tin mật khẩu!");
                                    }

                                    if (res)
                                    {
                                        session.CommitTransactionAsync();
                                    }
                                    else
                                    {
                                        session.AbortTransactionAsync();
                                    }
                                }
                                catch (Exception ex)
                                {
                                    session.AbortTransactionAsync();
                                    throw ex;
                                    throw;
                                }
                            }
                        }
                        else
                        {
                            _Setting.Message.SetMessage("Phiên giao dịch đã hết hạn!");
                        }
                    }
                    else
                    {
                        _Setting.Message.SetMessage("Mã OTP không đúng!");
                    }
                }
                else
                {
                    _Setting.Message.SetMessage("Không tìm thấy thông tin giao dịch!");
                }
            }
            else
            {
                _Setting.Message.SetMessage("Không tìm thấy thông tin người dùng!");
            }

            return(res);
        }