Пример #1
0
        public ActionResult Register(RegisterViewModel mem)
        {
            // make sure model is valid
            if (ModelState.IsValid)
            {
                if (MemberDB.DoesUsernameExist(mem.Username))
                {
                    ModelState.AddModelError("DuplicateUsername", "Username is already taken");

                    return(View(mem));
                }

                // if valid add to DB
                Member m = new Member()
                {
                    Username = mem.Username,
                    Password = mem.Password,
                    Email    = mem.Email,
                };
                MemberDB.RegisterMember(m);
                SessionHelper.LogUserIn(m);
                return(RedirectToAction("Index", "Home"));
            }
            // if invalid, return view w/ errors
            return(View(mem));
        }