Ejemplo n.º 1
0
        public async Task <Content> CalculateContentListAsync(int sequence, Site site, int currentChannelId, Content source, List <ContentColumn> columns)
        {
            if (source == null)
            {
                return(null);
            }

            var channel = await _databaseManager.ChannelRepository.GetAsync(source.ChannelId);

            var content = await _pathManager.DecodeContentAsync(site, channel, source);

            content.Set(State, CheckManager.GetCheckState(site, content));

            foreach (var column in columns)
            {
                if (!ListUtils.ContainsIgnoreCase(CalculatedAttributes, column.AttributeName))
                {
                    continue;
                }

                if (column.InputType == InputType.TextEditor)
                {
                    content.Set(column.AttributeName, string.Empty);
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, Sequence))
                {
                    content.Set(Sequence, sequence);
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, nameof(Content.ChannelId)))
                {
                    var channelName = await _databaseManager.ChannelRepository.GetChannelNameNavigationAsync(source.SiteId, currentChannelId, source.ChannelId);

                    content.Set(ChannelName, channelName);
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, nameof(Content.AdminId)))
                {
                    var adminName = await _databaseManager.AdministratorRepository.GetDisplayAsync(source.AdminId);

                    content.Set(AdminName, adminName);
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, nameof(Content.LastEditAdminId)))
                {
                    var lastEditAdminName =
                        await _databaseManager.AdministratorRepository.GetDisplayAsync(source.LastEditAdminId);

                    content.Set(LastEditAdminName, lastEditAdminName);
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, nameof(Content.UserId)))
                {
                    var userName = await _databaseManager.UserRepository.GetDisplayAsync(source.UserId);

                    content.Set(UserName, userName);
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, CheckAdminId))
                {
                    var checkedId = source.Get <int?>(CheckAdminId);
                    if (checkedId.HasValue)
                    {
                        var checkAdminName =
                            await _databaseManager.AdministratorRepository.GetDisplayAsync(checkedId.Value);

                        content.Set(CheckAdminName, checkAdminName);
                    }
                }
                else if (StringUtils.EqualsIgnoreCase(column.AttributeName, nameof(Content.SourceId)))
                {
                    var sourceName = await SourceManager.GetSourceNameAsync(_databaseManager, source.SiteId, source.SourceId);

                    content.Set(SourceName, sourceName);
                }
            }

            //if (pluginColumns != null)
            //{
            //    foreach (var pluginId in pluginColumns.Keys)
            //    {
            //        var contentColumns = pluginColumns[pluginId];
            //        if (contentColumns == null || contentColumns.Count == 0) continue;

            //        foreach (var columnName in contentColumns.Keys)
            //        {
            //            var attributeName = $"{pluginId}:{columnName}";
            //            if (columns.All(x => x.AttributeName != attributeName)) continue;

            //            try
            //            {
            //                var func = contentColumns[columnName];
            //                var value = func(new ContentContextImpl
            //                {
            //                    SiteId = source.SiteId,
            //                    ChannelId = source.ChannelId,
            //                    ContentId = source.Id
            //                });

            //                content.Set(attributeName, value);
            //            }
            //            catch (Exception ex)
            //            {
            //                await _databaseManager.ErrorLogRepository.AddErrorLogAsync(pluginId, ex);
            //            }
            //        }
            //    }
            //}

            return(content);
        }