public IActionResult Index() { AdminModel model = new AdminModel(); model = _db.AdminModel.FirstOrDefault(); model.Balance = TRTLService.GetTRTLBalance(model.PaymentAddress).availableBalance; return(View(model)); }
public async Task <IViewComponentResult> InvokeAsync() { FooterStats model = new FooterStats(); model.ActivePlayers = _db.Users.Where(u => u.EmailConfirmed == true).Count(); var adminModel = _db.AdminModel.FirstOrDefault(); if (adminModel != null) { model.WalletBalance = TRTLService.GetTRTLBalance(adminModel.PaymentAddress).availableBalance; } return(View(model)); }
private decimal getAnimalProducePrice() { AdminModel adminModel = _db.AdminModel.FirstOrDefault(); AddressBalance balance = TRTLService.GetTRTLBalance(adminModel.PaymentAddress); decimal allDeposits = balance.availableBalance; var allAnimals = _db.Animals.ToList(); var allUserAnimals = _db.UserAnimals.GroupBy(ua => ua.AnimalId).ToList(); long totalClaimCount = 0; foreach (var userAnimal in allUserAnimals) { var tmpSum = userAnimal.Sum(ua => ua.AnimalCount) * allAnimals.Where(a => a.Id == userAnimal.First().AnimalId).FirstOrDefault().ProductionSpeed; totalClaimCount += Convert.ToInt64(tmpSum); } decimal unitPrice = 0; if (totalClaimCount > 0) { unitPrice = allDeposits / totalClaimCount / 60;//ROI factor HARDCODED - at least 60 days(if you count off refs and other factors) } return(unitPrice); }
public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } var user = await _userManager.GetUserAsync(User); if (user == null) { return(NotFound($"Unable to load user with ID '{_userManager.GetUserId(User)}'.")); } if (Input.WithdrawAmount < 20) { TempData["ERROR"] = "Minimum withdrawal is 20 TRTL"; return(Page()); } if (Input.WithdrawAmount > user.TRTLBalance) { TempData["ERROR"] = "You tried to withdraw more than you have"; return(Page()); } var adminModel = _db.AdminModel.FirstOrDefault(); var GameBalance = TRTLService.GetTRTLBalance(adminModel.PaymentAddress); /*amount to withdraw would exceed balance*/ if ((GameBalance.availableBalance) < Input.WithdrawAmount) { TempData["ERROR"] = "Internal error 1"; return(Page()); } string WithdrawAddress = Input.WithdrawAddress; float WithdrawalFeeDev = (5f / 100f); float WithdrawAmount = Input.WithdrawAmount - ((float)Input.WithdrawAmount * WithdrawalFeeDev); int WithdrawAmountForFeeCalculation = (int)Math.Ceiling(WithdrawAmount); float feeCalculated = TRTLService.GetTRTLFee(float.Parse(WithdrawAmountForFeeCalculation.ToString())); var transfer = TRTLService.TransferTRTL( from: _db.AdminModel.FirstOrDefault().PaymentAddress, to: WithdrawAddress, amount: float.Parse((WithdrawAmount + feeCalculated).ToString("n2")), fee: (float)0.1 ); if (transfer != null && transfer.transactionHash != null && transfer.transactionHash.Length > 0) { if (_db.Withdrawals.Where(w => w.transactionHash == transfer.transactionHash).FirstOrDefault() == null) { _db.Withdrawals.Add(new Withdrawal() { transactionHash = transfer.transactionHash }); } user.TRTLBalance -= Input.WithdrawAmount; user.TRTLWithdrawnTotal += Input.WithdrawAmount; _db.Users.Update(user); _db.SaveChanges(); TempData["SUCCESS"] = "Withdrawal of " + WithdrawAmount + " TRTL successfull. Withdrawal hash is: " + transfer.transactionHash; } else { TempData["ERROR"] = "Internal error. Please contact admin or try different amount."; } return(Page()); }