public ActionResult New(UsersNew form)
        {
            var user = new User();
            SyncRoles(form.Roles, user.Roles);

            if(Database.Session.Query<User>().Any(a => a.Username == form.Username))
                ModelState.AddModelError("Username", "Username must be unique.");

            if (!ModelState.IsValid)
                return View(form);

            user.Email = form.Email;
            user.Username = form.Username;
            user.SetPassword(form.Password);

            Database.Session.Save(user);

            return RedirectToAction("Index");
        }
        public ActionResult New(UsersNew form)
        {
            if (Database.Session.Query<User>().Any(u => u.Username == form.Username))
                ModelState.AddModelError("Username", "Username must be unique");

            if (!ModelState.IsValid)
                return View(form);

            var user = new User
            {
                Email = form.Email,
                Username = form.Username
            };

            user.SetPassword(form.Password);

            Database.Session.Save(user);

            return RedirectToAction("index");
        }
Beispiel #3
0
        public ActionResult New(UsersNew newUserFormData)
        {
            var user = new User();

            SyncUserRoles.Sync(newUserFormData.Roles, user.Roles);

            if (Database.Session.Query<User>().Any(u => u.Username == newUserFormData.Username))
                ModelState.AddModelError("Username", "Username must be unique");

            if (!ModelState.IsValid)
                return View(newUserFormData);

            user.Email = newUserFormData.Email;
            user.Username = newUserFormData.Username;
            user.SetPassword(newUserFormData.Password);

            Database.Session.Save(user);

            return RedirectToAction("index");
        }