Ejemplo n.º 1
0
        public questStatus Read(UserId userId, out UserEditorViewModel userEditorViewModel)
        {
            // Initialize
            questStatus status = null;

            userEditorViewModel = null;


            // Read
            Quest.Functional.ASM.User user = null;
            UsersMgr usersMgr = new UsersMgr(this.UserSession);

            status = usersMgr.Read(userId, out user);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Transfer model.
            userEditorViewModel = new UserEditorViewModel(this.UserSession);
            BufferMgr.TransferBuffer(user, userEditorViewModel);



            return(new questStatus(Severity.Success));
        }
        public questStatus Read(UserPrivilegesViewModel viewModel, out UserPrivilegesViewModel userPrivilegesViewModel)
        {
            // Initialize
            questStatus status = null;

            userPrivilegesViewModel = null;
            UserId userId = new UserId(viewModel.Id);


            // Get the user
            User     user     = null;
            UsersMgr usersMgr = new UsersMgr(this.UserSession);

            status = usersMgr.Read(userId, out user);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


            // Get privileges
            List <SearchField> searchFieldList = new List <SearchField>();
            SearchOptions      searchOptions   = new SearchOptions();

            searchOptions.SearchFieldList = searchFieldList;
            QueryOptions queryOptions = new QueryOptions();

            queryOptions.SearchOptions = searchOptions;
            QueryResponse queryResponse = null;

            List <Privilege> privilegeList = null;
            PrivilegesMgr    privilegesMgr = new PrivilegesMgr(this.UserSession);

            status = privilegesMgr.List(queryOptions, out privilegeList, out queryResponse);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


            // Get user privileges
            List <Privilege> userPrivilegeList = null;
            AccountMgr       accountMgr        = new AccountMgr(this.UserSession);

            status = accountMgr.GetUserPrivileges(userId, out userPrivilegeList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Remove from privileges lists whatever privileges the user is already in.
            List <Privilege> unassignedPrivilegeList = new List <Privilege>();

            foreach (Privilege privilege in privilegeList)
            {
                Privilege userPrivilege = userPrivilegeList.Find(delegate(Privilege g) { return(g.Id == privilege.Id); });
                if (userPrivilege == null)
                {
                    unassignedPrivilegeList.Add(privilege);
                }
            }

            // Sort privilege lists
            unassignedPrivilegeList.Sort(delegate(Privilege i1, Privilege i2) { return(i1.Name.CompareTo(i2.Name)); });
            userPrivilegeList.Sort(delegate(Privilege i1, Privilege i2) { return(i1.Name.CompareTo(i2.Name)); });


            // Transfer model
            userPrivilegesViewModel = new UserPrivilegesViewModel(this.UserSession, viewModel);
            UserEditorViewModel userEditorViewModel = new UserEditorViewModel();

            BufferMgr.TransferBuffer(user, userEditorViewModel);
            userPrivilegesViewModel.User = userEditorViewModel;
            foreach (Privilege privilege in unassignedPrivilegeList)
            {
                BootstrapTreenodeViewModel privilegeNode = null;
                status = FormatBootstrapTreeviewNode(privilege, out privilegeNode);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                privilegeNode.icon = "fa fa-lock padding-right-20";
                userPrivilegesViewModel.Privileges.Add(privilegeNode);
            }
            foreach (Privilege privilege in userPrivilegeList)
            {
                BootstrapTreenodeViewModel userPrivilegeNode = null;
                status = FormatBootstrapTreeviewNode(privilege, out userPrivilegeNode);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                userPrivilegeNode.icon = "fa fa-unlock padding-right-20";
                userPrivilegesViewModel.UserPrivileges.Add(userPrivilegeNode);
            }
            return(new questStatus(Severity.Success));
        }
        public questStatus Read(UserGroupsViewModel viewModel, out UserGroupsViewModel userGroupsViewModel)
        {
            // Initialize
            questStatus status = null;

            userGroupsViewModel = null;
            UserId userId = new UserId(viewModel.Id);


            // Get the user
            User     user     = null;
            UsersMgr usersMgr = new UsersMgr(this.UserSession);

            status = usersMgr.Read(userId, out user);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


            // Get groups
            List <SearchField> searchFieldList = new List <SearchField>();
            SearchOptions      searchOptions   = new SearchOptions();

            searchOptions.SearchFieldList = searchFieldList;
            QueryOptions queryOptions = new QueryOptions();

            queryOptions.SearchOptions = searchOptions;
            QueryResponse queryResponse = null;

            List <Group> groupList = null;
            GroupsMgr    groupsMgr = new GroupsMgr(this.UserSession);

            status = groupsMgr.List(queryOptions, out groupList, out queryResponse);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }


            // Get user groups
            List <Group> userGroupList = null;
            AccountMgr   accountMgr    = new AccountMgr(this.UserSession);

            status = accountMgr.GetUserGroups(userId, out userGroupList);
            if (!questStatusDef.IsSuccess(status))
            {
                return(status);
            }

            // Remove from groups lists whatever groups the user is already in.
            List <Group> unassignedGroupList = new List <Group>();

            foreach (Group group in groupList)
            {
                Group userGroup = userGroupList.Find(delegate(Group g) { return(g.Id == group.Id); });
                if (userGroup == null)
                {
                    unassignedGroupList.Add(group);
                }
            }

            // Sort group lists
            unassignedGroupList.Sort(delegate(Group i1, Group i2) { return(i1.Name.CompareTo(i2.Name)); });
            userGroupList.Sort(delegate(Group i1, Group i2) { return(i1.Name.CompareTo(i2.Name)); });


            // Transfer model
            userGroupsViewModel = new UserGroupsViewModel(this.UserSession, viewModel);
            UserEditorViewModel userEditorViewModel = new UserEditorViewModel();

            BufferMgr.TransferBuffer(user, userEditorViewModel);
            userGroupsViewModel.User = userEditorViewModel;
            foreach (Group group in unassignedGroupList)
            {
                BootstrapTreenodeViewModel groupNode = null;
                status = FormatBootstrapTreeviewNode(group, out groupNode);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                userGroupsViewModel.Groups.Add(groupNode);
            }
            foreach (Group group in userGroupList)
            {
                BootstrapTreenodeViewModel userGroupNode = null;
                status = FormatBootstrapTreeviewNode(group, out userGroupNode);
                if (!questStatusDef.IsSuccess(status))
                {
                    return(status);
                }
                userGroupsViewModel.UserGroups.Add(userGroupNode);
            }
            return(new questStatus(Severity.Success));
        }