private void btnEdit_Click(object sender, EventArgs e)
        {
            Int64 currentPay = Int64.Parse(txtPayed.Text);

            if (txtPayed.Text != string.Empty && txtPayed.Text != "0" && currentPay <= MaxPay())
            {
                string Type = txtMSHD.Text.Trim().Substring(0, 2);
                if (Type == "NH")
                {
                    PaymentInputBO paymentInputBO = new PaymentInputBO();
                    PaymentInput   payment        = new PaymentInput();
                    payment.ID       = int.Parse(txtMSTT.Text.Substring(2));
                    payment.Date     = DateTime.Parse(txtDate.Text);
                    payment.MSDH     = int.Parse(txtMSHD.Text.Trim().Substring(2));
                    payment.isDelete = false;
                    payment.Payment  = int.Parse(txtPayed.Text);
                    paymentInputBO.Update(payment);
                }
                else
                {
                    PaymentOutputBO paymentOutputBO = new PaymentOutputBO();
                    PaymentOutput   payment         = new PaymentOutput();
                    payment.ID       = int.Parse(txtMSTT.Text.Substring(2));
                    payment.Date     = DateTime.Parse(txtDate.Text);
                    payment.MSDH     = int.Parse(txtMSHD.Text.Trim().Substring(2));
                    payment.isDelete = false;
                    payment.Payment  = int.Parse(txtPayed.Text);
                    paymentOutputBO.Update(payment);
                }
                this.Close();
            }
            else
            {
                MessageBox.Show("Không hợp lệ .Vui lòng kiểm tra lại");
                txtPayed.Text = MaxPay().ToString();
            }
        }
Beispiel #2
0
        public async Task <PaymentOutput> PurchaseTokens(WalletLogsDto input)
        {
            try
            {
                if (input != null)
                {
                    var user = _userRepository.Get(input.UserId);


                    var dcnt   = input.Amount;
                    var dollar = dcnt * _dcntInUsd;
                    var dcntInBtcOrEthOrUsd = dollar;

                    var currency = await _currenciesRepository.FirstOrDefaultAsync(input.CurrencyId);

                    if (!currency.IsCrypto)
                    {
                        var users = await UserManager.GetUsersInRoleAsync("Admin");

                        var instruction = users.FirstOrDefault(item => item.WiredInstruction != null).WiredInstruction;
                        return(new PaymentOutput()
                        {
                            Instruction = instruction
                        });
                    }
                    if (currency == null)
                    {
                        throw new UserFriendlyException(L("CurrencyNotFound"));
                    }

                    var exchangeRate = await _exchangeRateRepository.FirstOrDefaultAsync(e => e.CurrencyId.Equals(currency.Id));

                    if (exchangeRate == null)
                    {
                        throw new UserFriendlyException(L("CurrencyNotFound"));
                    }

                    if (currency.IsCrypto)
                    {
                        if (Convert.ToDouble(input.Amount) != 0.0)
                        {
                            dcntInBtcOrEthOrUsd = (_dcntInUsd * input.Amount) / exchangeRate.Price;
                        }
                    }

                    var transaction = new Transaction()
                    {
                        UserId    = input.UserId,
                        AmountDue = dcntInBtcOrEthOrUsd,
                        //TODO: old CurrencyType = (int)Enum.Parse(typeof(CurrentTypeEnum), input.CurrentType),
                        WalletId          = input.WalletId,
                        CurrencyId        = currency.Id,
                        TransactionStatus = TransactionStatusEnum.Commited,
                        IsDeleted         = false,
                        FirstName         = user.Name,
                        LastName          = user.Surname,
                        TokensIssued      = (long)input.Amount,
                        EmailAddress      = user.EmailAddress,
                        TransactionDate   = DateTime.Now,
                        TenantId          = AbpSession.TenantId
                    };
                    await _walletLogsRepository.InsertAsync(transaction);

                    QRCodeGenerator        qrGenerator = new QRCodeGenerator();
                    var                    walletId    = (await _supportedCurrencyRepository.FirstOrDefaultAsync(x => x.CurrencyId == currency.Id)).WalletId;
                    QRCodeData             qrCodeData  = qrGenerator.CreateQrCode(walletId, QRCodeGenerator.ECCLevel.Q);
                    QRCode                 qrCode      = new QRCode(qrCodeData);
                    Bitmap                 qrCodeImage = qrCode.GetGraphic(4);
                    System.IO.MemoryStream ms          = new System.IO.MemoryStream();
                    qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
                    byte[] byteImage    = ms.ToArray();
                    var    qrCodeBase64 = Convert.ToBase64String(byteImage);

                    var qrcodeDto = new PaymentOutput()
                    {
                        QrCode  = qrCodeBase64,
                        Address = walletId
                    };

                    var tenant = await _tenantRepository.FirstOrDefaultAsync(item => item.Id == AbpSession.TenantId);

                    var currencyImage = StoreClientAgreement(ms, currency.Name);
                    //TODO email
                    //Uri uri = new Uri(tenant.LogoUrl);
                    var emailData = new DcntEmailTemplateInput()
                    {
                        UserName            = user.Name,
                        WalletId            = walletId,
                        Amount              = input.Amount,
                        CurrentType         = currency.Name,
                        Dcnt                = dcnt,
                        Dollar              = dollar,
                        Uri                 = tenant.LogoUrl,
                        DcntInBtcOrEthOrUsd = dcntInBtcOrEthOrUsd,
                        QrCode              = currencyImage
                    };

                    var receiver = new MailAddress(user.EmailAddress, user.FullName);
                    var body     = _userEmailer.GetDCEmailTemplate(emailData);
                    await _userEmailer.SendEmailWithSendGrid(receiver, body);

                    return(qrcodeDto);
                }
            }
            catch (Exception ex)
            {
            }
            return(new PaymentOutput());
        }