Exemplo n.º 1
0
        public override async Task <IDisplayResult> UpdateAsync(LinkAdminNode treeNode, IUpdateModel updater)
        {
            var model = new LinkAdminNodeViewModel();

            if (await updater.TryUpdateModelAsync(model, Prefix, x => x.LinkUrl, x => x.LinkText, x => x.IconClass, x => x.PermissionIds))
            {
                treeNode.LinkText  = model.LinkText;
                treeNode.LinkUrl   = model.LinkUrl;
                treeNode.IconClass = model.IconClass;

                var modifiedPermissions = (model.PermissionIds == null ? new string[0] : model.PermissionIds.Split(',', StringSplitOptions.RemoveEmptyEntries));
                //clear the old permissions to insert all every time
                treeNode.Permissions.Clear();

                //change permissions only if one is inserted
                if (modifiedPermissions.Length > 0)
                {
                    var permissions = await _permissionService.GetInstalledPermissionsAsync();

                    foreach (var permissionName in modifiedPermissions)
                    {
                        var perm = permissions.Where(p => p.Name == permissionName).FirstOrDefault();

                        if (perm != null)
                        {
                            treeNode.Permissions.Add(perm);
                        }
                    }
                }
            }
            ;

            return(Edit(treeNode));
        }
Exemplo n.º 2
0
        public override async Task <IDisplayResult> UpdateAsync(LinkAdminNode treeNode, IUpdateModel updater)
        {
            var model = new LinkAdminNodeViewModel();

            if (await updater.TryUpdateModelAsync(model, Prefix, x => x.LinkUrl, x => x.LinkText, x => x.IconClass))
            {
                treeNode.LinkText  = model.LinkText;
                treeNode.LinkUrl   = model.LinkUrl;
                treeNode.IconClass = model.IconClass;
            }
            ;

            return(Edit(treeNode));
        }
Exemplo n.º 3
0
        public override async Task <IDisplayResult> UpdateAsync(LinkAdminNode treeNode, IUpdateModel updater)
        {
            var model = new LinkAdminNodeViewModel();

            if (await updater.TryUpdateModelAsync(model, Prefix, x => x.LinkUrl, x => x.LinkText, x => x.IconClass, x => x.SelectedPermissionNames))
            {
                treeNode.LinkText  = model.LinkText;
                treeNode.LinkUrl   = model.LinkUrl;
                treeNode.IconClass = model.IconClass;

                var selectedPermissions = (model.SelectedPermissionNames == null ? Array.Empty <string>() : model.SelectedPermissionNames.Split(',', StringSplitOptions.RemoveEmptyEntries));

                var permissions = await _adminMenuPermissionService.GetPermissionsAsync();

                treeNode.PermissionNames = permissions
                                           .Where(p => selectedPermissions.Contains(p.Name))
                                           .Select(p => p.Name).ToArray();
            }

            return(Edit(treeNode));
        }