public OxiteViewModelItem <Role> ItemEdit(RoleAddress roleAddress)
        {
            Role role = null;

            if (roleAddress != null && !string.IsNullOrEmpty(roleAddress.RoleName))
            {
                role = roleService.GetRole(roleAddress);

                if (role == null)
                {
                    return(null);
                }
            }

            return(new OxiteViewModelItem <Role>(role));
        }
        public void RemoveRole(RoleAddress roleAddress)
        {
            using (TransactionScope transaction = new TransactionScope())
            {
                Role role = repository.GetRole(roleAddress.RoleName);

                if (role != null)
                {
                    if (repository.Remove(roleAddress.RoleName))
                    {
                        transaction.Complete();

                        pluginEngine.ExecuteAll("RoleRemoved", new { context, role = new RoleReadOnly(role) });

                        return;
                    }
                }
            }
        }
        public object ItemSave(RoleAddress roleAddress, RoleInput roleInput)
        {
            ModelResult <Role> results;

            if (roleAddress != null && !string.IsNullOrEmpty(roleAddress.RoleName))
            {
                results = roleService.EditRole(roleAddress, roleInput);
            }
            else
            {
                results = roleService.AddRole(roleInput);
            }

            if (!results.IsValid)
            {
                ModelState.AddModelErrors(results.ValidationState);

                return(ItemEdit(roleAddress));
            }

            return(Redirect(Url.AppPath(Url.ManageUsers())));
        }
        public ModelResult <Role> EditRole(RoleAddress roleAddress, RoleInput roleInput)
        {
            ValidationStateDictionary validationState = new ValidationStateDictionary();

            validationState.Add(typeof(RoleInput), validator.Validate(roleInput));

            if (!validationState.IsValid)
            {
                return(new ModelResult <Role>(validationState));
            }

            Role originalRole;
            Role newRole;

            using (TransactionScope transaction = new TransactionScope())
            {
                originalRole = repository.GetRole(roleAddress.RoleName);
                newRole      = originalRole.Apply(roleInput);

                validateRole(newRole, originalRole, validationState);

                if (!validationState.IsValid)
                {
                    return(new ModelResult <Role>(validationState));
                }

                newRole = repository.Save(newRole);

                transaction.Complete();
            }

            pluginEngine.ExecuteAll("RoleSaved", new { context, role = new RoleReadOnly(newRole) });
            pluginEngine.ExecuteAll("RoleEdited", new { context, role = new RoleReadOnly(newRole), roleOriginal = new RoleReadOnly(originalRole) });

            return(new ModelResult <Role>(newRole, validationState));
        }
 public Role GetRole(RoleAddress roleAddress)
 {
     return(repository.GetRole(roleAddress.RoleName));
 }
        public object ItemRemove(RoleAddress roleAddress)
        {
            roleService.RemoveRole(roleAddress);

            return(Redirect(Url.AppPath(Url.ManageUsers())));
        }