示例#1
0
        public ActionResult Delete(Guid id)
        {
            var userService = new UserService(Context);
            userService.Delete(id);

            return RedirectToAction("List");
        }
示例#2
0
        public ActionResult Register(UsersViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Users = Context.Users.ToList();
                model.Roles = Context.Roles.ToList();

                return View("List", model);
            }

            if (Context.Users.Any(x => x.Login == model.NewUserLogin))
            {
                ModelState.AddModelError("NewUserLogin", string.Format("A user with username {0} already exists", model.NewUserLogin));
                model.Users = Context.Users.ToList();
                model.Roles = Context.Roles.ToList();

                return View("List", model);
            }

            if (model.NewUserPassword != model.NewUserConfirmPassword)
            {
                ModelState.AddModelError("NewUserConfirmPassword", "Passwords do not match");
                model.Users = Context.Users.ToList();
                model.Roles = Context.Roles.ToList();

                return View("List", model);
            }

            var userService = new UserService(Context);
            userService.Register(model.NewUserLogin, model.NewUserPassword, model.NewUserFirstName, model.NewUserLastName, model.NewUserRole);

            return RedirectToAction("List");
        }