DeleteDeptExcutor.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. using LJLib.SQLEX;
  14. namespace JLHHJSvr.Excutor
  15. {
  16. internal sealed class DeleteDeptExcutor : ExcutorBase<DeleteDeptRequest, DeleteDeptResponse>
  17. {
  18. protected override void ExcuteInternal(DeleteDeptRequest request, object state, DeleteDeptResponse rslt)
  19. {
  20. var tokendata = BllHelper.GetToken(request.token);
  21. if (tokendata == null)
  22. {
  23. rslt.ErrMsg = "会话已经中断,请重新登录";
  24. return;
  25. }
  26. if (!request.list.Any())
  27. {
  28. rslt.ErrMsg = "至少提交一条需要删除的记录";
  29. return;
  30. }
  31. using (var con = GlobalVar.ConnectionString.NewSqlConnection())
  32. using (var cmd = con.CreateCommand())
  33. {
  34. con.Open();
  35. using (cmd.Transaction = con.BeginTransaction())
  36. {
  37. try
  38. {
  39. foreach(var dept in request.list)
  40. {
  41. if(DbSqlHelper.Delete(cmd, dept) == 0)
  42. {
  43. throw new LJCommonException($"部门:{dept.deptname}不存在");
  44. }
  45. }
  46. cmd.Transaction.Commit();
  47. }
  48. catch (Exception e)
  49. {
  50. cmd.Transaction.Rollback();
  51. rslt.ErrMsg = e.ToString();
  52. }
  53. }
  54. }
  55. }
  56. }
  57. }