public async Task <IActionResult> Register(Member m)
        {
            if (ModelState.IsValid)
            {
                bool isEmailAndUsernameAvailable = true;
                if (await MemberDb.IsEmailTaken(_context, m.EmailAddress))
                {
                    isEmailAndUsernameAvailable = false;
                    ModelState.AddModelError(string.Empty, "Email address is taken");
                }
                if (await MemberDb.IsUsernameTaken(_context, m.Username))
                {
                    isEmailAndUsernameAvailable = false;
                    ModelState.AddModelError(string.Empty, "Username is taken");
                }

                if (!isEmailAndUsernameAvailable)
                {
                    return(View(m));
                }

                await MemberDb.Add(_context, m);

                SessionHelper.LogUserIn(_httpAccessor, m.MemberId, m.Username);
                TempData["Message"] = "You registered sucessfully";
                return(RedirectToAction("Index", "Home"));
            }

            return(View(m));
        }
Beispiel #2
0
        public async Task <IActionResult> Register(Member m)
        {
            if (ModelState.IsValid)
            {
                await MemberDb.Add(_context, m);

                SessionHelper.LogUserIn(_httpAccessor, m.MemberId, m.Username);
                TempData["Message"] = $"Welcome {m.Username} to Tanner's Game Emporium!";
                return(RedirectToAction("Index", "Home"));
            }

            return(View(m));
        }