コード例 #1
0
        public async Task <ActionResult <BoolResult> > Add([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.SettingsContentTag))
            {
                return(Unauthorized());
            }

            foreach (var tagName in request.TagNames)
            {
                await _contentTagRepository.InsertAsync(request.SiteId, tagName);
            }

            await _authManager.AddSiteLogAsync(request.SiteId, "新增内容标签", $"内容标签:{ListUtils.ToString(request.TagNames)}");

            return(new BoolResult
            {
                Value = true
            });
        }
コード例 #2
0
        public async Task <ActionResult <BoolResult> > Submit([FromBody] SubmitRequest request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.Contents) ||
                !await _authManager.HasContentPermissionsAsync(request.SiteId, request.ChannelId, Types.ContentPermissions.Edit))
            {
                return(Unauthorized());
            }

            var site = await _siteRepository.GetAsync(request.SiteId);

            if (site == null)
            {
                return(NotFound());
            }

            var allTagNames = await _contentTagRepository.GetTagNamesAsync(request.SiteId);

            foreach (var tagName in request.TagNames)
            {
                if (!allTagNames.Contains(tagName))
                {
                    await _contentTagRepository.InsertAsync(request.SiteId, tagName);
                }
            }

            var summaries = ContentUtility.ParseSummaries(request.ChannelContentIds);

            foreach (var summary in summaries)
            {
                var channel = await _channelRepository.GetAsync(summary.ChannelId);

                var content = await _contentRepository.GetAsync(site, channel, summary.Id);

                if (content == null)
                {
                    continue;
                }

                var list = new List <string>();
                foreach (var tagName in ListUtils.GetStringList(content.TagNames))
                {
                    if (allTagNames.Contains(tagName))
                    {
                        list.Add(tagName);
                    }
                }

                foreach (var name in request.TagNames)
                {
                    if (request.IsCancel)
                    {
                        if (list.Contains(name))
                        {
                            list.Remove(name);
                        }
                    }
                    else
                    {
                        if (!list.Contains(name))
                        {
                            list.Add(name);
                        }
                    }
                }
                content.TagNames = list;

                await _contentRepository.UpdateAsync(site, channel, content);
            }

            await _authManager.AddSiteLogAsync(request.SiteId, request.IsCancel? "批量取消内容标签" : "批量设置内容标签");

            return(new BoolResult
            {
                Value = true
            });
        }