Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        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())));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
 public Role GetRole(RoleAddress roleAddress)
 {
     return(repository.GetRole(roleAddress.RoleName));
 }
Ejemplo n.º 6
0
        public object ItemRemove(RoleAddress roleAddress)
        {
            roleService.RemoveRole(roleAddress);

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