예제 #1
0
        public async Task <IActionResult> OnPost()
        {
            //login functionality
            var userx = await _userManager.FindByNameAsync(username);

            if (userx != null)
            {
                //sign in
                var signInResult = _signInManager.PasswordSignInAsync(userx, pass, false, false);

                if (signInResult.Result.Succeeded)
                {
                    Knowledge.UserOptions _uo2 = _context.Uoptions.FirstOrDefault(p => p.user == userx);
                    if (_uo2 != null)
                    {
                        _uo.ID = _uo2.ID; _uo.toLang = _uo2.toLang; _uo.fromLang = _uo2.fromLang;
                    }
                    else
                    {
                        int maxid = _context.Uoptions.Max(s => (int?)s.ID) ?? 1;
                        _uo = new Knowledge.UserOptions {
                            user = userx, toLang = Lang.ENG, fromLang = Lang.RUS
                        };
                        _context.Uoptions.Add(_uo);
                        _context.SaveChanges();
                    }
                    return(RedirectToPage("/Account/Options"));
                }
            }
            return(RedirectToPage("/Account/Options"));
        }
예제 #2
0
 //public
 public OptionsModel(UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager,
                     Knowledge.UserOptions uo, RazorPagesKnowContext context)
 {
     _userManager   = userManager;
     _signInManager = signInManager;
     _context       = context;
     _uo            = uo;
 }
예제 #3
0
        public void OnGet()
        {
            SelectList langs = new SelectList(Enum.GetNames(typeof(Lang)));

            if (_signInManager.IsSignedIn(User))
            {
                uName = User.Identity.Name;

                Knowledge.UserOptions _uo2 = _context.Uoptions.FirstOrDefault(p => p.user.UserName == User.Identity.Name);
                ll = _uo2.toLang; nl = _uo2.fromLang;
                if (_uo2 != null)
                {
                    _uo = _uo2;
                }
            }
        }