public ActionResult Edit(int id, UsersEdit form)
        {
            var user = Database.Session.Load<User>(id);
            if (user == null)
                return HttpNotFound();

            if (Database.Session.Query<User>().Any(u => u.Username == form.Username && u.Id != id))
                ModelState.AddModelError("Username", "Username must be unique");

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

            user.Username = form.Username;
            user.Email = form.Email;
            Database.Session.Update(user);

            return RedirectToAction("index");
        }
Exemplo n.º 2
0
        public ActionResult Edit(int id, UsersEdit form)
        {
            var user = Database.Session.Load<User>(id);
            if (user == null)
                return HttpNotFound();

            SyncRoles(form.Roles, user.Roles);
            //check id as well because the user can set the username to the one they have
            if (Database.Session.Query<User>().Any(u => u.Username == form.Username && u.Id != id))
                ModelState.AddModelError("Username", "Username must be unique");

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

            user.Username = form.Username;
            user.Email = form.Email;
            Database.Session.Update(user);

            return RedirectToAction("index");
        }
Exemplo n.º 3
0
        public ActionResult Edit(int id, UsersEdit updatedUserFormData)
        {
            var userToBeUpdated = Database.Session.Load<User>(id);

            if (userToBeUpdated == null)
                return HttpNotFound();

            SyncUserRoles.Sync(updatedUserFormData.Roles, userToBeUpdated.Roles);

            if (Database.Session.Query<User>().Any(u => u.Username == updatedUserFormData.Username && u.Id != id))
                ModelState.AddModelError("Username", "Username must be unique");

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

            userToBeUpdated.Username = updatedUserFormData.Username;
            userToBeUpdated.Email = updatedUserFormData.Email;

            Database.Session.Update(userToBeUpdated);

            return RedirectToAction("index");
        }