Exemple #1
0
 public async Task DeleteAsync()
 {
     await _bookRepository.DeleteAsync(new Book()
     {
         Id = 7
     });
 }
        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);
        }