示例#1
0
        /// <summary>
        /// Get toolbar for current user
        /// </summary>
        /// <returns></returns>
        public ToolbarRenderModel GetCurrentUserToolbar()
        {
            if (WorkContext.CurrentUser != null)
            {
                var toolbars =
                    _userGroupService.Fetch(g => WorkContext.CurrentUser.GroupIds.Contains(g.Id) && g.ToolbarId.HasValue)
                    .Select(g => g.Toolbar);

                var basicTools = new List <string>();
                var pageTools  = new List <string>();

                if (toolbars.Any())
                {
                    foreach (var toolbar in toolbars)
                    {
                        var basic = SerializeUtilities.Deserialize <List <string> >(toolbar.BasicToolbar);
                        basicTools.AddRange(basic ?? new List <string>());

                        var page = SerializeUtilities.Deserialize <List <string> >(toolbar.PageToolbar);
                        pageTools.AddRange(page ?? new List <string>());
                    }

                    return(new ToolbarRenderModel
                    {
                        BasicTools = basicTools.Distinct().ToList(),
                        PageTools = pageTools.Distinct().ToList()
                    });
                }
            }

            var defaultToolbar = FetchFirst(t => t.IsDefault);

            if (defaultToolbar != null)
            {
                return(new ToolbarRenderModel(defaultToolbar));
            }

            return(new ToolbarRenderModel());
        }