TopicService.Delete.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Threading.Tasks;
  5. using System.Transactions;
  6. using Datory;
  7. using GxPress.Entity.Topic;
  8. namespace GxPress.Service.Implement.Topic
  9. {
  10. public partial class TopicService
  11. {
  12. /// <summary>
  13. /// 删除话题
  14. /// </summary>
  15. /// <param name="id"></param>
  16. /// <returns></returns>
  17. public async Task<bool> DeleteAsync(int id)
  18. {
  19. try
  20. {
  21. using (TransactionScope transactionScope = new TransactionScope())
  22. {
  23. //删除话题
  24. await _topicRepository.DeleteAsync(id);
  25. //删除话题用户
  26. await _topicAddresseeRepository.DeleteAsync(Q.Where(nameof(TopicAddressee.TopicId), id));
  27. transactionScope.Complete();
  28. }
  29. }
  30. catch (Exception e)
  31. {
  32. Console.WriteLine(e);
  33. throw;
  34. }
  35. return true;
  36. }
  37. }
  38. }