protected void CurrentUserTransactionsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { var commands = new[] { "Confirm", "ConfirmReceived" }; if (commands.Contains(e.CommandName)) { var index = e.GetSelectedRowIndex() % CurrentUserTransactionsGridView.PageSize; var row = CurrentUserTransactionsGridView.Rows[index]; var TransactionId = (row.Cells[0].Text.Trim()); var Transaction = new CryptocurrencyTradeTransaction(Convert.ToInt32(TransactionId)); switch (e.CommandName) { case "Confirm": Transaction.PaymentStatus = CryptocurrencyTransactionStatus.AwaitingPaymentConfirmation; Transaction.Save(); break; case "ConfirmReceived": break; } CurrentUserTransactionsGridView.DataBind(); } }
protected void CurrentUserTransactionsGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.Header) { e.Row.Cells[1].Text = L1.AMOUNT; e.Row.Cells[2].Text = U6010.EXECUTIONTIME; e.Row.Cells[3].Text = L1.STATUS; e.Row.Cells[5].Text = U4200.TIMELEFT; e.Row.Cells[6].Text = L1.DESCRIPTION; } if (e.Row.RowType == DataControlRowType.DataRow) { //Loading data for addiotional info var CurrentTransaction = new CryptocurrencyTradeTransaction(Int32.Parse(e.Row.Cells[0].Text)); var CurrentOffer = new CryptocurrencyTradeOffer(CurrentTransaction.OfferId); e.Row.Cells[1].Text = CryptocurrencyMoney.Parse(e.Row.Cells[1].Text).ToString(); if ((CryptocurrencyTransactionStatus)Int32.Parse(e.Row.Cells[3].Text) == CryptocurrencyTransactionStatus.AwaitingPaymentConfirmation) { e.Row.Cells[6].Visible = true; } else { e.Row.Cells[6].Visible = false; } e.Row.Cells[3].Text = HtmlCreator.GetColoredTransactionStatus((CryptocurrencyTransactionStatus)Int32.Parse(e.Row.Cells[3].Text)); //Count Time Left in Escrow DateTime ExecutionTime = DateTime.Parse(e.Row.Cells[2].Text); TimeSpan TimeLeft = AppSettings.ServerTime - ExecutionTime; int TimeLeftMinutes = CurrentOffer.EscrowTime - (int)TimeLeft.TotalMinutes; if (TimeLeftMinutes < 0) { TimeLeftMinutes = 0; } Label OfferTimeLeftToPayTextBox = new Label(); OfferTimeLeftToPayTextBox.Text = HtmlCreator.GetColoredTime(TimeLeftMinutes); e.Row.Cells[5].Controls.Add(OfferTimeLeftToPayTextBox); //Load Description for this offerAddToCryptocurrencyBalance Label OfferDescriptionTextBox = new Label(); //If seller description have data, that means that it is 100% buy offer and tehre is no desc, we have to load seller's description if (String.IsNullOrEmpty(CurrentTransaction.SellerDescription) || String.IsNullOrWhiteSpace(CurrentTransaction.SellerDescription)) { OfferDescriptionTextBox.Text = CurrentOffer.Description; } else { OfferDescriptionTextBox.Text = CurrentTransaction.SellerDescription; } OfferDescriptionTextBox.CssClass = "description-column displaynone"; e.Row.Cells[4].Controls.Add(OfferDescriptionTextBox); } }
protected void CurrentUserTransactionsGridView_RowCommand(object sender, GridViewCommandEventArgs e) { var commands = new[] { "ConfirmReceived" }; if (commands.Contains(e.CommandName)) { var index = e.GetSelectedRowIndex() % CurrentUserTransactionsGridView.PageSize; var row = CurrentUserTransactionsGridView.Rows[index]; var TransactionId = (row.Cells[0].Text.Trim()); var Transaction = new CryptocurrencyTradeTransaction(Convert.ToInt32(TransactionId)); var CurrentTradeOffer = new CryptocurrencyTradeOffer(Transaction.OfferId); switch (e.CommandName) { case "ConfirmReceived": int ClientWithCash = -1; if (Transaction.ClientId != Member.CurrentId) { ClientWithCash = Transaction.ClientId; } else { ClientWithCash = CurrentTradeOffer.CreatorId; } var BuyerWithCash = new Member(ClientWithCash); BuyerWithCash.AddToCryptocurrencyBalance(CryptocurrencyType.BTC, Transaction.CCAmount.ToDecimal(), "Cryptocurrency trade", BalanceLogType.CryptocurrencyTrade); Transaction.PaymentStatus = CryptocurrencyTransactionStatus.Finished; Transaction.Save(); CryptocurrencyFinishedTradeOffer.CreateNewTemplate(Transaction.OfferId, ClientWithCash, Member.CurrentId, Transaction.CCAmount); break; } CurrentUserTransactionsGridView.DataBind(); } }
public static void CRON() { // IF CC ENABLED ? CryptocurrencyTradeTransaction.CheckIfEscrowPassedForAllActiveTransactions(); }
public static void TryPlaceOrder(int OfferId, CryptocurrencyMoney CCAmount, String SellerDescription) { //Loading selected offer var SelectedOffer = new CryptocurrencyTradeOffer(OfferId); var OfferCreator = new Member(SelectedOffer.CreatorId); //Checking Creator's Balance if (SelectedOffer.OfferKind == CryptocurrencyOfferType.Buy) { if (SelectedOffer.CreatorId != Member.CurrentId) { if (OfferCreator.GetCryptocurrencyBalance(CryptocurrencyType.BTC) < CCAmount) { throw new MsgException(U6010.ORDER_CREATORNOBALANCE); } } } else { if (SelectedOffer.CreatorId == Member.CurrentId) { if (OfferCreator.GetCryptocurrencyBalance(CryptocurrencyType.BTC) < CCAmount) { throw new MsgException(U6010.ORDER_YOUNOBALANCE); } } } //If everything is good, creating transaction CryptocurrencyTradeTransaction NewTransaction = new CryptocurrencyTradeTransaction() { OfferId = OfferId, ClientId = Member.CurrentId, ExecutionTime = AppSettings.ServerTime, PaymentStatus = CryptocurrencyTransactionStatus.AwaitingPayment, CCAmount = CCAmount, SellerDescription = SellerDescription }; //Freezing cryptocurrency for transaction time //Current user clicked sell if (SelectedOffer.OfferKind == CryptocurrencyOfferType.Buy) { Member.Current.SubtractFromCryptocurrencyBalance(CryptocurrencyType.BTC, CCAmount.ToDecimal(), "Cryptocurrency trade", BalanceLogType.CryptocurrencyTrade); } //Current user clicked buy else { OfferCreator.SubtractFromCryptocurrencyBalance(CryptocurrencyType.BTC, CCAmount.ToDecimal(), "Cryptocurrency trade", BalanceLogType.CryptocurrencyTrade); } //Descreasing existing offer CC amount left SelectedOffer.AmountLeft = SelectedOffer.AmountLeft - CCAmount; if (SelectedOffer.AmountLeft <= CryptocurrencyMoney.Zero) { SelectedOffer.Status = CryptocurrencyOfferStatus.Finished; } SelectedOffer.Save(); //Saving transaction, ESCROW starts here NewTransaction.Save(true); }
//Actual transactions protected void CurrentUserTransactionsGridView_DataSource_Init(object sender, EventArgs e) { CurrentUserTransactionsGridView_DataSource.SelectCommand = CryptocurrencyTradeTransaction.GetGridViewStringForUserActualTransactions(Member.CurrentId, CryptocurrencyOfferType.Buy); }