DeleteDeptExcutor.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.SqlClient;
  4. using System.Linq;
  5. using System.Text;
  6. using DirectService.Tools;
  7. using JLHHJSvr.BLL;
  8. using JLHHJSvr.Com;
  9. using JLHHJSvr.Com.Model;
  10. using JLHHJSvr.LJException;
  11. using LJLib.DAL.SQL;
  12. using LJLib.Net.SPI.Server;
  13. namespace JLHHJSvr.Excutor
  14. {
  15. internal sealed class DeleteDeptExcutor : ExcutorBase<DeleteDeptRequest, DeleteDeptResponse>
  16. {
  17. protected override void ExcuteInternal(DeleteDeptRequest request, object state, DeleteDeptResponse rslt)
  18. {
  19. var tokendata = BllHelper.GetToken(request.token);
  20. if (tokendata == null)
  21. {
  22. rslt.ErrMsg = "会话已经中断,请重新登录";
  23. return;
  24. }
  25. if (!request.list.Any())
  26. {
  27. rslt.ErrMsg = "至少提交一条需要删除的记录";
  28. return;
  29. }
  30. using (var con = new SqlConnection(GlobalVar.ConnectionString))
  31. using (var cmd = con.CreateCommand())
  32. {
  33. con.Open();
  34. using (cmd.Transaction = con.BeginTransaction())
  35. {
  36. try
  37. {
  38. foreach(var dept in request.list)
  39. {
  40. if(DbSqlHelper.Delete(cmd, dept) == 0)
  41. {
  42. throw new LJCommonException($"部门:{dept.deptname}不存在");
  43. }
  44. }
  45. cmd.Transaction.Commit();
  46. }
  47. catch (Exception e)
  48. {
  49. cmd.Transaction.Rollback();
  50. rslt.ErrMsg = e.ToString();
  51. }
  52. }
  53. }
  54. }
  55. }
  56. }