Example #1
0
        public async Task <ActionResult <GetResult> > Add([FromBody] ChannelGroup request)
        {
            if (!await _authManager.HasSitePermissionsAsync(request.SiteId,
                                                            Types.SitePermissions.SettingsContentGroup))
            {
                return(Unauthorized());
            }

            if (await _contentGroupRepository.IsExistsAsync(request.SiteId, request.GroupName))
            {
                return(this.Error("保存失败,已存在相同名称的内容组!"));
            }

            var groupInfo = new ContentGroup
            {
                SiteId      = request.SiteId,
                GroupName   = request.GroupName,
                Description = request.Description
            };

            await _contentGroupRepository.InsertAsync(groupInfo);

            await _authManager.AddSiteLogAsync(request.SiteId, "新增内容组", $"内容组:{groupInfo.GroupName}");

            var groups = await _contentGroupRepository.GetContentGroupsAsync(request.SiteId);

            return(new GetResult
            {
                Groups = groups
            });
        }
Example #2
0
        public async Task <ActionResult <ListResult> > Add([FromBody] AddRequest request)
        {
            if (await _contentGroupRepository.IsExistsAsync(request.SiteId, request.GroupName))
            {
                return(this.Error("保存失败,已存在相同名称的内容组!"));
            }

            var groupInfo = new ContentGroup
            {
                SiteId      = request.SiteId,
                GroupName   = request.GroupName,
                Description = request.Description
            };

            await _contentGroupRepository.InsertAsync(groupInfo);

            await _authManager.AddSiteLogAsync(request.SiteId, "新增内容组", $"内容组:{groupInfo.GroupName}");

            var groups = await _contentGroupRepository.GetContentGroupsAsync(request.SiteId);

            var groupNames = groups.Select(x => x.GroupName);

            return(new ListResult
            {
                GroupNames = groupNames,
                Groups = groups
            });
        }
Example #3
0
        public async Task <ActionResult <BoolResult> > Add([FromBody] AddRequest 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 channelContentIds = ContentUtility.ParseSummaries(request.ChannelContentIds);

            var group = new ContentGroup
            {
                GroupName   = request.GroupName,
                SiteId      = request.SiteId,
                Description = request.Description
            };

            if (await _contentGroupRepository.IsExistsAsync(request.SiteId, group.GroupName))
            {
                await _contentGroupRepository.UpdateAsync(group);

                await _authManager.AddSiteLogAsync(request.SiteId, "修改内容组", $"内容组:{group.GroupName}");
            }
            else
            {
                await _contentGroupRepository.InsertAsync(group);

                await _authManager.AddSiteLogAsync(request.SiteId, "添加内容组", $"内容组:{group.GroupName}");
            }

            foreach (var channelContentId in channelContentIds)
            {
                var channel = await _channelRepository.GetAsync(channelContentId.ChannelId);

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

                if (content == null)
                {
                    continue;
                }

                var list = ListUtils.GetStringList(content.GroupNames);
                if (!list.Contains(group.GroupName))
                {
                    list.Add(group.GroupName);
                }
                content.GroupNames = list;

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

            await _authManager.AddSiteLogAsync(request.SiteId, "批量设置内容组", $"内容组:{group.GroupName}");

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