public async Task UpdateAsync(Guid id, CreateUpdateChannelDto updateChannel)
        {
            Channel channel = await _channelRepository.Select.Where(r => r.Id == id).ToOneAsync();

            if (channel == null)
            {
                throw new LinCmsException("该数据不存在");
            }

            bool exist = _channelRepository.Select.Any(r => r.ChannelName == updateChannel.ChannelName && r.Id != id && r.ChannelCode == updateChannel.ChannelCode);

            if (exist)
            {
                throw new LinCmsException($"技术频道[{updateChannel.ChannelName}]已存在");
            }

            _mapper.Map(updateChannel, channel);

            var channelTagLists = new List <ChannelTag>();

            updateChannel.TagIds?.ForEach(r => { channelTagLists.Add(new ChannelTag(id, r)); });

            await _channelTagRepository.DeleteAsync(r => r.ChannelId == id);

            await _channelRepository.UpdateAsync(channel);

            await _channelTagRepository.InsertAsync(channelTagLists);
        }
        public async Task CreateAsync([FromBody] CreateUpdateChannelDto createChannel)
        {
            bool exist = await _channelRepository.Select.AnyAsync(r => r.ChannelName == createChannel.ChannelName && r.ChannelCode == createChannel.ChannelCode);

            if (exist)
            {
                throw new LinCmsException($"技术频道[{createChannel.ChannelName}]已存在");
            }

            Channel channel = _mapper.Map <Channel>(createChannel);

            channel.Tags = new List <Tag>();
            createChannel.TagIds?.ForEach(r =>
            {
                channel.Tags.Add(new Tag()
                {
                    Id = r
                });
            });

            await _channelRepository.InsertAsync(channel);
        }
Beispiel #3
0
 public UnifyResponseDto UpdateAsync(Guid id, [FromBody] CreateUpdateChannelDto updateChannel)
 {
     _channelService.UpdateAsync(id, updateChannel);
     return(UnifyResponseDto.Success("更新技术频道成功"));
 }
Beispiel #4
0
 public UnifyResponseDto CreateAsync([FromBody] CreateUpdateChannelDto createChannel)
 {
     _channelService.CreateAsync(createChannel);
     return(UnifyResponseDto.Success("新建技术频道成功"));
 }
Beispiel #5
0
        public ResultDto Put(Guid id, [FromBody] CreateUpdateChannelDto updateChannel)
        {
            _channelService.Put(id, updateChannel);

            return(ResultDto.Success("更新技术频道成功"));
        }
Beispiel #6
0
 public ResultDto Post([FromBody] CreateUpdateChannelDto createChannel)
 {
     _channelService.Post(createChannel);
     return(ResultDto.Success("新建技术频道成功"));
 }