public ActionResult Register(RegisterViewModel model) { var registeringEnabled = ConfigurationManager.AppSettings["RegisterEnabled"]; if (registeringEnabled == "true") { if (ModelState.IsValid) { var user = SimpleFactories.GetUserFromRegisterViewModel(model); var result = UserService.RegisterUser(user); if (result.Status) { UserService.SignIn(model.UserName, false); return(RedirectToAction("Index", "Home")); } else { for (int i = 0; i < result.ErrorCodes.Count; i++) { ModelState.AddModelError("", RegisterResult.GetErrorMessage(result.ErrorCodes[i])); } } } return(View(model)); } else { ModelState.AddModelError("", "Регистирањето е оневозможено. Обидете се подоцна"); return(View(model)); } }
//GET : /Authorization/AddRolesToUser/id{UserID} public ActionResult AddRolesToUser(int id) { var user = UserService.GetUser(id); var roles = RolesService.GetAllRoles(); var ViewModel = SimpleFactories.BuildAddRolesToUserviewModel(user, roles); return(View(ViewModel)); }
//GET: /Authorization/AddPrivilegeToRole?RoleName=name public ActionResult AddPrivilegeToRole(string RoleName) { var role = RolesService.GetRole(RoleName); var privileges = RolesService.GetAllPrivileges(); var viewModel = SimpleFactories.BuildAddPrivilegesToRoleViewModel(role, privileges); return(View(viewModel)); }
public ActionResult AddRolesToUser(int id, FormCollection collection) { var user = UserService.GetUser(id); var selectedRoles = StringHelpers.SplitStringToList(collection["roles"], ','); var result = RolesService.SetNewRolesToUser(user, selectedRoles); if (result.IsOK) { return(RedirectToAction("UserDetails", new { id = id })); } else { var allRoles = RolesService.GetAllRoles(); var viewModel = SimpleFactories.BuildAddRolesToUserviewModel(user, allRoles); foreach (var message in result.Messages) { ModelState.AddModelError("", message); } return(View(viewModel)); } }
public ActionResult AddPrivilegeToRole(string RoleName, FormCollection collection) { var selectedPrivileges = StringHelpers.SplitStringToList(collection["privileges"], ','); var result = RolesService.SetNewPrivilegesToRole(RoleName, selectedPrivileges); if (result.IsOK) { return(RedirectToAction("RoleDetails", new { RoleName = RoleName })); } else { var role = RolesService.GetRole(RoleName); var privileges = RolesService.GetAllPrivileges(); var viewModel = SimpleFactories.BuildAddPrivilegesToRoleViewModel(role, privileges); foreach (var message in result.Messages) { ModelState.AddModelError("", message); } return(View(viewModel)); } }