示例#1
0
        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));
            }
        }
示例#2
0
        //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));
        }
示例#3
0
        //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));
        }
示例#4
0
        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));
            }
        }
示例#5
0
        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));
            }
        }