// TODO: These can be more efficient, i.e. remove the wallet calls from GetHistory
        // And use a different model for Withdrawals. It doesn't quite map to the Withdrawal class.

        /// <summary>
        /// Get the history of successful withdrawals.
        /// </summary>
        /// <param name="maximumEntriesToReturn">The maximum number of entries to return.</param>
        /// <returns>A <see cref="WithdrawalModel"/> object containing a history of withdrawals.</returns>
        public List <WithdrawalModel> GetHistory(int maximumEntriesToReturn)
        {
            var result = new List <WithdrawalModel>();

            // Enumerate withdrawals starting with the most recent.
            IWithdrawal[] withdrawals = this.federationWalletManager.FindWithdrawalTransactions(sort: true)
                                        .Select(w => w.Item2)
                                        .Where(x => x.BlockHash != null)
                                        .Reverse()
                                        .Take(maximumEntriesToReturn)
                                        .ToArray();

            if (withdrawals.Length > 0)
            {
                ICrossChainTransfer[] transfers = this.crossChainTransferStore.QueryTransfersById(withdrawals.Select(w => w.DepositId).ToArray());

                for (int i = 0; i < withdrawals.Length; i++)
                {
                    ICrossChainTransfer transfer = transfers[i];
                    var model = new WithdrawalModel();
                    model.withdrawal     = withdrawals[i];
                    model.TransferStatus = transfer?.Status.ToString();
                    result.Add(model);
                }
            }

            return(result);
        }
Пример #2
0
        public Response <WithdrawalModel> Update(WithdrawalModel model)
        {
            try
            {
                var validationResult = this.withdrawalValidation.ValidateUpdate(model);
                if (!validationResult.IsValid)
                {
                    return new Response <WithdrawalModel>
                           {
                               Message    = validationResult.ErrorMessage,
                               ResultType = ResultType.ValidationError
                           }
                }
                ;

                this.withdrawalRepository.Update(model);
                this.withdrawalRepository.Save();

                return(new Response <WithdrawalModel>
                {
                    Result = model,
                    ResultType = ResultType.Success
                });
            }
            catch (Exception ex)
            {
                //online error log
                var err = ex.Message;
            }

            return(new Response <WithdrawalModel>
            {
                ResultType = ResultType.Error
            });
        }
Пример #3
0
        // TODO: These can be more efficient, i.e. remove the wallet calls from GetHistory
        // And use a different model for Withdrawals. It doesn't quite map to the Withdrawal class.

        /// <summary>
        /// Get the history of successful withdrawals.
        /// </summary>
        /// <param name="maximumEntriesToReturn">The maximum number of entries to return.</param>
        /// <returns>A <see cref="WithdrawalModel"/> object containing a history of withdrawals.</returns>
        public List <WithdrawalModel> GetHistory(int maximumEntriesToReturn)
        {
            var result = new List <WithdrawalModel>();

            ICrossChainTransfer[] transfers = this.crossChainTransferStore.GetTransfersByStatus(new[] { CrossChainTransferStatus.SeenInBlock });

            // TODO: Need to check if this is only used for wallet UI purposes and has no consensus implications
            foreach (ICrossChainTransfer transfer in transfers.OrderByDescending(t => t.BlockHeight)) // t.PartialTransaction.Time
            {
                if (maximumEntriesToReturn-- <= 0)
                {
                    break;
                }

                // Extract the withdrawal details from the recorded "PartialTransaction".
                IWithdrawal withdrawal = this.withdrawalExtractor.ExtractWithdrawalFromTransaction(transfer.PartialTransaction, transfer.BlockHash, (int)transfer.BlockHeight);

                var model = new WithdrawalModel();
                model.withdrawal     = withdrawal;
                model.TransferStatus = transfer?.Status.ToString();

                result.Add(model);
            }

            return(result);
        }
Пример #4
0
        //End Content Management

        //Withdrawal
        #region
        public int InsertWithdrawal(WithdrawalModel model)
        {
            int id = 0;

            using (MySqlConnection conn = new MySqlConnection(constr))
            {
                conn.Open();
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "INSERT INTO Withdrawal " +
                                      "(BankAccount, BankAccountName, BankAccountNumber, WithdrawalDate, WithdrawalAmount, GameType, Status, Username, ActionDate) " +
                                      "VALUES(@BankAccount, @BankAccountName, @BankAccountNumber, DATE_ADD(now(), INTERVAL 12 HOUR), @WithdrawalAmount, @GameType, 1, @UserName, null); SELECT LAST_INSERT_ID();";
                    cmd.Parameters.AddWithValue("BankAccount", Convert.ToInt32(model.BankAccount));
                    cmd.Parameters.AddWithValue("BankAccountName", model.BankAccountNameSubmit);
                    cmd.Parameters.AddWithValue("BankAccountNumber", model.BankAccountNumberSubmit);
                    cmd.Parameters.AddWithValue("WithdrawalAmount", model.WithdrawalAmount);
                    cmd.Parameters.AddWithValue("GameType", Convert.ToInt32(model.GameType));
                    cmd.Parameters.AddWithValue("UserName", model.UserName);
                    id = Convert.ToInt32(cmd.ExecuteScalar());
                }
                conn.Close();
            }
            return(id);
        }
Пример #5
0
        public ActionResult Index(WithdrawalModel withdrawalModel)
        {
            try
            {
                if (withdrawalModel.ValidationCode != Session["Captcha"].ToString())
                {
                    Session["message"]            = "Incorrect captcha!";
                    this.Session["requestStatus"] = (object)"Error";
                    return(RedirectToAction("Index"));
                }
                else if (withdrawalModel.BankAccount == 1 || withdrawalModel.GameType == 1 || withdrawalModel.WithdrawalAmount == 0 || withdrawalModel.UserName == null || withdrawalModel.UserName == "" || withdrawalModel.BankAccountNameSubmit == null || withdrawalModel.BankAccountNameSubmit == "" || withdrawalModel.BankAccountNumberSubmit == null || withdrawalModel.BankAccountNumberSubmit == "")
                {
                    Session["message"]            = "Data tidak sesuai!";
                    this.Session["requestStatus"] = (object)"Error";
                    return(RedirectToAction("Index"));
                }

                int withdrawalId = dal.InsertWithdrawal(withdrawalModel);
                dal.InsertNotification(withdrawalId, "withdrawal");
                Session["message"]       = "Permintaan withdraw berhasil diajukan. Petugas kami akan meninjau permintaan Anda dan Anda akan diinformasikan lebih lanjut kedepannya. Terima kasih.";
                Session["requestStatus"] = "Success";
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Session["message"]            = "Terjadi kesalahan pada proses pengajuan withdraw.";
                this.Session["requestStatus"] = (object)"Error";
                return(RedirectToAction("Index"));
            }
        }
        // TODO: These can be more efficient, i.e. remove the wallet calls from GetHistory
        // And use a different model for Withdrawals. It doesn't quite map to the Withdrawal class.

        /// <summary>
        /// Get the history of successful withdrawals.
        /// </summary>
        /// <param name="maximumEntriesToReturn">The maximum number of entries to return.</param>
        /// <returns>A <see cref="WithdrawalModel"/> object containing a history of withdrawals.</returns>
        public List <WithdrawalModel> GetHistory(int maximumEntriesToReturn)
        {
            var result = new List <WithdrawalModel>();

            ICrossChainTransfer[] transfers = this.crossChainTransferStore.GetTransfersByStatus(new[] { CrossChainTransferStatus.SeenInBlock });

            foreach (ICrossChainTransfer transfer in transfers.OrderByDescending(t => t.BlockHeight))
            {
                if (maximumEntriesToReturn-- <= 0)
                {
                    break;
                }

                // Extract the withdrawal details from the recorded "PartialTransaction".
                IWithdrawal withdrawal = this.withdrawalExtractor.ExtractWithdrawalFromTransaction(transfer.PartialTransaction, transfer.BlockHash, (int)transfer.BlockHeight);

                var model = new WithdrawalModel();
                model.withdrawal     = withdrawal;
                model.TransferStatus = transfer?.Status.ToString();

                result.Add(model);
            }

            return(result);
        }
Пример #7
0
        public async Task <bool> Create([FromBody] WithdrawalModel model)
        {
            try
            {
                var wd = new Withdrawal();

                wd.SourceWallet   = model.SourceWallet;
                wd.TargetWallet   = model.TargetWallet;
                wd.Asset          = model.Asset;
                wd.Size           = model.Size;
                wd.Signature      = model.Signature;
                wd.TimeStampTicks = model.Timestamp;
                wd.OracleAdrress  = model.OracleAddress;
                wd.OracleFee      = model.OracleFee;
                wd.BuildHash();

                return(await repository.AppendWithdrawal(wd));
            }
            catch (Exception e)
            {
                e.ToString();
            }

            return(false);
        }
Пример #8
0
        /// <summary>
        /// Get pending withdrawals.
        /// </summary>
        /// <param name="crossChainTransfers">The list of transfers to report on.</param>
        /// <returns>A <see cref="WithdrawalModel"/> object containing pending withdrawals and statuses.</returns>
        public List <WithdrawalModel> GetPendingWithdrawals(IEnumerable <ICrossChainTransfer> crossChainTransfers)
        {
            var result = new List <WithdrawalModel>();

            foreach (ICrossChainTransfer transfer in crossChainTransfers)
            {
                var    model  = new WithdrawalModel(this.network, transfer);
                string status = transfer?.Status.ToString();
                switch (transfer?.Status)
                {
                case CrossChainTransferStatus.FullySigned:
                    if (this.mempoolManager.InfoAsync(model.Id).GetAwaiter().GetResult() != null)
                    {
                        status += "+InMempool";
                    }

                    model.SpendingOutputDetails = this.GetSpendingInfo(transfer.PartialTransaction);
                    break;

                case CrossChainTransferStatus.Partial:
                    model.SignatureCount = transfer.GetSignatureCount(this.network);
                    status += " (" + model.SignatureCount + "/" + this.federatedPegSettings.MultiSigM + ")";
                    model.SpendingOutputDetails = this.GetSpendingInfo(transfer.PartialTransaction);
                    break;
                }

                model.TransferStatus = status;

                result.Add(model);
            }

            return(result);
        }
Пример #9
0
        public ServiceResult <WithdrawalResult> Withdrawal(WithdrawalModel model)
        {
            var result = new ServiceResult <WithdrawalResult>();

            if (!ModelState.IsValid)
            {
                result.Code = ReasonCode.MISSING_REQUIRED_FIELDS;
                foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)))
                {
                    result.Message += error + Environment.NewLine;
                }

                return(result);
            }
            var ip = this.GetClientIPAddress();

            var accountId = this.GetMerchantAccountId();

            var data = new MerchantWalletComponent().Withdrawal(accountId, model.Amount, model.CryptoId, model.Address, model.Tag, ip);

            result.Data = new WithdrawalResult
            {
                Id        = data.Id,
                Timestamp = data.Timestamp.ToUnixTime(),
                OrderNo   = data.OrderNo
            };

            result.Success();
            return(result);
        }
Пример #10
0
        public async Task <IActionResult> Withdrawal(Guid accountId, [FromBody] WithdrawalModel model, CancellationToken token)
        {
            var command = new WithdrawalCommand {
                AccountId = accountId,
                Amount    = model.Amount,
            };

            var response = await mediator.Send(command, token);

            return(Ok(response));
        }
Пример #11
0
        public ActionResult Insert()
        {
            WithdrawalModel model = new WithdrawalModel();

            var bankAccount = dal.GetBanks();

            ViewBag.BankAccount = new SelectList(bankAccount, "Id", "BankName");

            var gameType = dal.GetGameTypes();

            ViewBag.GameType = new SelectList(gameType, "Id", "GameType");

            return(PartialView("WithdrawalModal", model));
        }
Пример #12
0
        public ValidationResult ValidateUpdate(WithdrawalModel model)
        {
            this.validationResult = new ValidationResult();

            if (model == null)
            {
                this.validationResult.AddErrorMessage(ResourceDesignation.Invalid_Designation);
                return(this.validationResult);
            }

            this.ValidateName(model.EmployeeId);

            return(this.validationResult);
        }
Пример #13
0
        /// <summary>
        /// Get pending withdrawals.
        /// </summary>
        /// <returns>A <see cref="WithdrawalModel"/> object containing pending withdrawals and statuses.</returns>
        public List <WithdrawalModel> GetPending()
        {
            var result = new List <WithdrawalModel>();

            // Get all Suspended, all Partial, and all FullySigned transfers.
            ICrossChainTransfer[] inProgressTransfers = this.crossChainTransferStore.GetTransfersByStatus(new CrossChainTransferStatus[]
            {
                CrossChainTransferStatus.Suspended,
                CrossChainTransferStatus.Partial,
                CrossChainTransferStatus.FullySigned
            }, true, false);

            foreach (ICrossChainTransfer transfer in inProgressTransfers)
            {
                var model = new WithdrawalModel();
                model.withdrawal = new Withdrawal(
                    transfer.DepositTransactionId,
                    transfer.PartialTransaction?.GetHash(),
                    transfer.DepositAmount,
                    transfer.DepositTargetAddress.GetDestinationAddress(this.network).ToString(),
                    transfer.BlockHeight ?? 0,
                    transfer.BlockHash
                    );

                string status = transfer?.Status.ToString();
                switch (transfer?.Status)
                {
                case CrossChainTransferStatus.FullySigned:
                    if (this.mempoolManager.InfoAsync(model.withdrawal.Id).GetAwaiter().GetResult() != null)
                    {
                        status += "+InMempool";
                    }

                    model.SpendingOutputDetails = this.GetSpendingInfo(transfer.PartialTransaction);
                    break;

                case CrossChainTransferStatus.Partial:
                    status += " (" + transfer.GetSignatureCount(this.network) + "/" + this.federatedPegSettings.MultiSigM + ")";
                    model.SpendingOutputDetails = this.GetSpendingInfo(transfer.PartialTransaction);
                    break;
                }

                model.TransferStatus = status;

                result.Add(model);
            }

            return(result);
        }
Пример #14
0
        public ActionResult Withdrawal(WithdrawalModel model)
        {
            Users    user        = Session["User"] as Users;
            Accounts bankAccount = new Accounts(bankDB.Accounts.Find(user.UserID));

            List <SqlParameter> param = new List <SqlParameter>();

            param.Add(new SqlParameter("@id", user.UserID));
            param.Add(new SqlParameter("@cash", (bankAccount.TotalCash - model.AmountToWithdrawal)));
            object[] parameters = param.ToArray();

            bankDB.Database.ExecuteSqlCommand("UPDATE dbo.Accounts SET TotalCash = @cash WHERE UserID = @id", parameters);

            return(RedirectToAction("Index", "Home"));
        }
Пример #15
0
        public ActionResult EditNotes(int id)
        {
            try
            {
                WithdrawalModel model = dal.GetWithdrawalById(id);

                return(PartialView("WithdrawalNotesModal", model));
            }
            catch (Exception ex)
            {
                Session["message"]       = "Unable to perform this request";
                Session["requestStatus"] = "Error";
                return(RedirectToAction("Index"));
            }
        }
Пример #16
0
 public ActionResult EditNotes(WithdrawalModel withdrawalModel)
 {
     try
     {
         dal.EditWithdrawalNotes(withdrawalModel);
         Session["message"]       = "Notes is successfully edited";
         Session["requestStatus"] = "Success";
         return(RedirectToAction("Index"));
     }
     catch
     {
         Session["message"]       = "Unable to perform this request";
         Session["requestStatus"] = "Error";
         return(RedirectToAction("Index"));
     }
 }
Пример #17
0
 public ActionResult Index(WithdrawalModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             BankSingleton.GetBank().LoggedInAccount.Withdraw(model.Amount);
         }
         catch (Exception e)
         {
             ModelState.AddModelError("", e.Message);
             return(View(model));
         }
         return(RedirectToAction("Index", "Home"));
     }
     return(View(model));
 }
Пример #18
0
        public ActionResult WithDrawAl(WithdrawalModel withdrawal)
        {
            if (ModelState.IsValid)
            {
                using (var db = new OurDbContext())
                {
                    var account = db.UserAccounts.FirstOrDefault(a => a.FriendlyName == withdrawal.MyAccount &&
                                                                 a.User.UserName == User.Identity.Name);
                    if (account == null)
                    {
                        return(RedirectToAction("Error"));
                    }

                    var transaction = new Transaction
                    {
                        UserAccountId = account.Id,
                        Key           = Guid.NewGuid(),
                        Type          = TransactionType.Withdrawal,
                        EvenDate      = DateTime.Now,
                        Amount        = withdrawal.Balance,
                        Comment       = "Направено е теглене от банкова сметка " + account.FriendlyName + " на стойност от " + withdrawal.Balance + " лв."
                    };
                    db.Transactions.Add(transaction);
                    if (transaction.Amount < 0)
                    {
                        ModelState.AddModelError(string.Empty, "Грешка! Не може сумата която искате да изтеглите да е отрицателна.");

                        return(View());
                    }


                    if (account.Balance < withdrawal.Balance)
                    {
                        ModelState.AddModelError(string.Empty, "Грешка! Нямате достатъчно пари, за да направите теглене. Вашата сума пари е " + account.Balance + " лв.");
                        return(View());
                    }

                    account.Balance = account.Balance - transaction.Amount;
                    db.SaveChanges();
                }
                return(RedirectToAction("WithDrawAlSuccessfully"));
            }

            return(View());
        }
Пример #19
0
        public List <WithdrawalModel> GetLatestWithdrawals()
        {
            WithdrawalModel        wm;
            List <WithdrawalModel> lwm = new List <WithdrawalModel>();

            using (MySqlConnection conn = new MySqlConnection(constr))
            {
                conn.Open();

                using (MySqlCommand cmd = new MySqlCommand())
                {
                    cmd.Connection = conn;

                    cmd.CommandText = "SELECT * FROM withdrawal WHERE Status = 2 ORDER BY WithdrawalDate DESC LIMIT 15";

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            wm    = new WithdrawalModel();
                            wm.Id = Convert.ToInt32(reader["id"]);
                            //wm.UserName = reader["username"].ToString().Remove(reader["username"].ToString().Length - 3) + "***";
                            wm.UserName = reader["username"].ToString();
                            for (int i = 1; i <= wm.UserName.Length; i++)
                            {
                                if (i % 2 != 0)
                                {
                                    wm.UserName = wm.UserName.Substring(0, i - 1) + "*" + wm.UserName.Substring(i, wm.UserName.Length - i);
                                }
                            }

                            wm.WithdrawalAmount = Convert.ToDecimal(reader["withdrawalamount"]);

                            lwm.Add(wm);
                        }
                    }

                    conn.Close();
                }
            }

            return(lwm);
        }
Пример #20
0
        /// <summary>
        /// Get the history of successful withdrawals.
        /// </summary>
        /// <param name="crossChainTransfers">The list of transfers to report on.</param>
        /// <param name="maximumEntriesToReturn">The maximum number of entries to return.</param>
        /// <returns>A <see cref="WithdrawalModel"/> object containing a history of withdrawals.</returns>
        public List <WithdrawalModel> GetHistory(IEnumerable <ICrossChainTransfer> crossChainTransfers, int maximumEntriesToReturn)
        {
            var result = new List <WithdrawalModel>();

            foreach (ICrossChainTransfer transfer in crossChainTransfers.OrderByDescending(t => t.BlockHeight))
            {
                if (maximumEntriesToReturn-- <= 0)
                {
                    break;
                }

                // Extract the withdrawal details from the recorded "PartialTransaction".
                IWithdrawal withdrawal = this.withdrawalExtractor.ExtractWithdrawalFromTransaction(transfer.PartialTransaction, transfer.BlockHash, (int)transfer.BlockHeight);
                var         model      = new WithdrawalModel(this.network, withdrawal, transfer);
                result.Add(model);
            }

            return(result);
        }
Пример #21
0
        public ActionResult WithdrawMoney(WithdrawalModel model)
        {
            var cardNumber       = (long)Session["CardNumber"];
            var withdrawalResult = BusinessController.WithdrawMoney(cardNumber,
                                                                    model.WithdrawalAmmount);

            if (withdrawalResult.Successfull)
            {
                return(View("WithdrawalResultView", new WithdrawalResultModel
                {
                    Amount = model.WithdrawalAmmount,
                    Balance = withdrawalResult.Balance,
                    CardNumber = cardNumber,
                    DateTime = DateTime.Now
                }));
            }
            return(View("ErrorView", new ErrorModel {
                ErrorText = "Not enough money on account", PreviousAction = "ShowWithdrawal"
            }));
        }
Пример #22
0
        public IActionResult Withdrawal([FromBody] WithdrawalModel model)
        {
            var user = _userService.GetByPassword(model.Password);

            if (user == null)
            {
                return(NotFound());
            }

            if (user.CurrentBalance < model.Amount)
            {
                return(BadRequest(new { message = "Insufficient funds!" }));
            }

            var balance = Decimal.ToInt32(user.CurrentBalance) - model.Amount;

            user.CurrentBalance = Convert.ToDecimal(balance);
            _userService.Update(user, model.Password);
            return(Ok());
        }
Пример #23
0
        /// <summary>
        /// Get the history of withdrawals and statuses.
        /// </summary>
        /// <param name="maximumEntriesToReturn">The maximum number of entries to return.</param>
        /// <returns>A <see cref="WithdrawalModel"/> object containing a history of withdrawals and statuses.</returns>
        public List <WithdrawalModel> GetHistory(int maximumEntriesToReturn)
        {
            var result = new List <WithdrawalModel>();

            IWithdrawal[] withdrawals = this.federationWalletManager.GetWithdrawals().Take(maximumEntriesToReturn).ToArray();

            if (withdrawals.Length > 0)
            {
                ICrossChainTransfer[] transfers = this.crossChainTransferStore.GetAsync(withdrawals.Select(w => w.DepositId).ToArray()).GetAwaiter().GetResult().ToArray();

                for (int i = 0; i < withdrawals.Length; i++)
                {
                    ICrossChainTransfer transfer = transfers[i];
                    var model = new WithdrawalModel();
                    model.withdrawal = withdrawals[i];
                    string status = transfer?.Status.ToString();
                    switch (transfer?.Status)
                    {
                    case CrossChainTransferStatus.FullySigned:
                        if (this.mempoolManager.InfoAsync(model.withdrawal.Id).GetAwaiter().GetResult() != null)
                        {
                            status += "+InMempool";
                        }

                        model.SpendingOutputDetails = this.GetSpendingInfo(transfer.PartialTransaction);
                        break;

                    case CrossChainTransferStatus.Partial:
                        status += " (" + transfer.GetSignatureCount(this.network) + "/" + this.federationGatewaySettings.MultiSigM + ")";
                        model.SpendingOutputDetails = this.GetSpendingInfo(transfer.PartialTransaction);
                        break;
                    }

                    model.TransferStatus = status;
                    result.Add(model);
                }
            }

            return(result);
        }
Пример #24
0
        public ActionResult Insert(WithdrawalModel withdrawalModel)
        {
            try
            {
                if (withdrawalModel.UserName == null || withdrawalModel.UserName == "" || withdrawalModel.BankAccount == 1 || withdrawalModel.GameType == 1 || withdrawalModel.BankAccountName == null || withdrawalModel.BankAccountName == "" || withdrawalModel.BankAccountNumber == null || withdrawalModel.BankAccountNumber == "" || withdrawalModel.WithdrawalAmount == 0)
                {
                    Session["message"]       = "Please fill in all the required fields.";
                    Session["requestStatus"] = "Error";
                    return(RedirectToAction("Index"));
                }

                dal.InsertWithdrawal(withdrawalModel);
                Session["message"]       = "Withdrawal is successfully added";
                Session["requestStatus"] = "Success";
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                Session["message"]       = "Unable to perform this request";
                Session["requestStatus"] = "Error";
                return(RedirectToAction("Index"));
            }
        }