Ejemplo n.º 1
0
        public async Task <IActionResult> ProfileApplication(Investment_Info invest, Account_Info account)
        {
            if (ModelState.IsValid)
            {
                //Get the existing user from the database
                var user = await _userManager.GetUserAsync(User);

                //check if user already filled out the investment Questions
                var entity = _context.UserInvestment.FirstOrDefault(i => i.UserID == user.Id);

                if (entity != null)
                {
                    //update user investment question

                    //convert Ques1 & Ques2 to all Capital Letter
                    invest.Ques1 = invest.Ques1.ToUpper();
                    invest.Ques2 = invest.Ques2.ToUpper();

                    //Append User signature to User Record
                    user.Signature     = invest.Signature;
                    user.FirstAccessed = false;
                    await _userManager.UpdateAsync(user);

                    _logger.LogInformation("User signature appended updated");

                    //Append UserID to User's investment Record
                    entity.FormType = "User Profile";

                    _context.UserInvestment.Update(entity);
                    _context.SaveChanges();
                    _logger.LogInformation("User investment info Updated");
                }
                else
                {
                    //convert Ques1 & Ques2 to all Capital Letter
                    invest.Ques1.ToUpper();
                    invest.Ques2.ToUpper();

                    //Append User signature to User Record
                    user.Signature     = invest.Signature;
                    user.FirstAccessed = false;
                    await _userManager.UpdateAsync(user);

                    _logger.LogInformation("User signature appended and firstAccessed value updated");

                    //Append UserID to User's investment Record
                    invest.UserID   = user.Id;
                    invest.FormType = "User Profile";
                    _context.UserInvestment.Add(invest);
                    _logger.LogInformation("User beneficiary and investment background added.");
                }

                return(RedirectToAction("Index", "Account"));
            }

            return(View());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> StocksAccount(Investment_Info invest, Account_Info account)
        {
            if (ModelState.IsValid)
            {
                //Get the existing user from the database
                var user = await _userManager.GetUserAsync(User);

                //check if user already filled out the investment Questions
                var entity = _context.UserInvestment.FirstOrDefault(i => i.UserID == user.Id);

                if (entity != null)
                {
                    //convert Ques1 & Ques2 to all Capital Letter
                    entity.Ques1 = invest.Ques1.ToUpper();
                    entity.Ques2 = invest.Ques2.ToUpper();

                    //Append User signature to User Record
                    user.Signature     = invest.Signature;
                    user.FirstAccessed = false;
                    await _userManager.UpdateAsync(user);

                    _logger.LogInformation("User signature appended updated");

                    //Append UserID to User's investment Record
                    entity.FormType = "Stocks Account";

                    _context.UserInvestment.Update(entity);
                    _context.SaveChanges();
                    _logger.LogInformation("User investment info Updated");
                }
                else
                {
                    //convert Ques1 & Ques2 to all Capital Letter
                    invest.Ques1.ToUpper();
                    invest.Ques2.ToUpper();

                    //Append User signature to User Record
                    user.Signature     = invest.Signature;
                    user.FirstAccessed = false;
                    await _userManager.UpdateAsync(user);

                    _logger.LogInformation("User signature appended and firstAccessed value updated");

                    //Append UserID to User's investment Record
                    invest.UserID   = user.Id;
                    invest.FormType = "Stocks Account";
                    _context.UserInvestment.Add(invest);
                    _logger.LogInformation("User beneficiary and investment background added.");
                }


                //check if user already has an account with us
                var check = _context.UserAccount.FirstOrDefault(i => i.UserID == user.Id);

                if (check != null)
                {
                    //Create User Account
                    check.AccountName      = user.FirstName + " " + " " + user.LastName; //concat user first and last name together and store it in AccountName
                    check.AccountType      = "Stocks";
                    check.AccountVersion   = invest.FormType;
                    check.AvailableBalance = 0.00f;
                    check.ActualBalance    = 0.00f;
                    check.WithdrawalAmount = 0.00f;
                    check.DepositAmount    = 0.00f;
                    check.AccountStatus    = "Active";
                    //account.UserID = user.Id;

                    _context.UserAccount.Update(check);
                    _context.SaveChanges();
                    _logger.LogInformation("User Account Upgraded");
                }
                else
                {
                    //Create User Account
                    account.AccountName      = user.FirstName + " " + " " + user.LastName; //concat user first and last name together and store it in AccountName
                    account.AccountType      = "Stocks";
                    account.AccountVersion   = invest.FormType;
                    account.AvailableBalance = 0.00f;
                    account.ActualBalance    = 0.00f;
                    account.WithdrawalAmount = 0.00f;
                    account.DepositAmount    = 0.00f;
                    account.AccountStatus    = "Active";
                    account.UserID           = user.Id;

                    _context.UserAccount.Add(account);
                    _logger.LogInformation("User stocks account created.");

                    await _context.SaveChangesAsync();
                }

                return(RedirectToAction("Index", "Profile"));
            }

            return(View());
        }