using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Transactions;
using Datory;
using GxPress.Entity.Topic;

namespace GxPress.Service.Implement.Topic
{
    public partial class TopicService
    {
        /// <summary>
        /// 删除话题
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<bool> DeleteAsync(int id)
        {
            try
            {
                using (TransactionScope transactionScope = new TransactionScope())
                {
                    //删除话题
                    await _topicRepository.DeleteAsync(id);
                    //删除话题用户
                    await _topicAddresseeRepository.DeleteAsync(Q.Where(nameof(TopicAddressee.TopicId), id));
                    transactionScope.Complete();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }

            return true;
        }
    }
}
