Ejemplo n.º 1
0
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            string userId      = _userManager.GetUserId(HttpContext.User);
            var    transaction = await _context.Transactions
                                 .Include(t => t.Trade)
                                 .Include(t => t.User)
                                 .Where(u => u.UserId == userId)
                                 .FirstOrDefaultAsync(m => m.Id == id);

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


            // decimal balance= await _tradeHelperService.getUserCashBalance(transaction);
            //  ViewData["Balance"]=balance;
            ViewData["Balance"] = TradeHelperService.readConfigurationSetting("InitialFund");

            return(View(transaction));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                // getting a new account initial balance from appsettings.json
                decimal balance = 0;
                if (decimal.TryParse(TradeHelperService.readConfigurationSetting("InitialFund"), out balance))
                {
                }

                var user = new FantasyWealthUser
                {
                    UserName          = Input.Email,
                    Email             = Input.Email,
                    FirstName         = Input.FirstName,
                    LastName          = Input.LastName,
                    RegistrationDate  = DateTime.Now,
                    CashBalanceAmount = balance
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    // creating transaction for a new account
                    await _tradeHelper.initiateFund(balance, user.Id);  // creating transaction for a new account

                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }