TsysRoleHandServices.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using AutoMapper;
  2. using Microsoft.EntityFrameworkCore;
  3. using Org.BouncyCastle.Utilities;
  4. using Ropin.Inspection.Common.Accessor.Interface;
  5. using Ropin.Inspection.Model.Entities;
  6. using Ropin.Inspection.Model.ViewModel.SYS;
  7. using Ropin.Inspection.Repository;
  8. using Ropin.Inspection.Repository.Interface;
  9. using Ropin.Inspection.Repository.SYS.Interface;
  10. using Ropin.Inspection.Service.SYS.Interface;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. namespace Ropin.Inspection.Service.SYS
  17. {
  18. internal class TsysRoleHandServices : ITsysRoleHandServices
  19. {
  20. private readonly IsysRoleHandRepository _repository;
  21. private readonly IMapper _mapper;
  22. private readonly IClaimsAccessor _claims;
  23. public TsysRoleHandServices(IClaimsAccessor claims, IsysRoleHandRepository repository, IMapper mapper)
  24. {
  25. _repository = repository;
  26. _mapper = mapper;
  27. _claims = claims;
  28. }
  29. public async Task CreateOneAsync(TSYSRoleHandViewModel viewModel)
  30. {
  31. var content = _mapper.Map<TSYS_RoleHand>(viewModel);
  32. content.C_CreateBy = _claims.ApiUserId;
  33. content.D_CreateOn = DateTime.Now;
  34. _repository.Create(content);
  35. var result = await _repository.SaveAsync();
  36. if (!result)
  37. {
  38. throw new Exception("创建失败");
  39. }
  40. }
  41. public async Task CreateAsync(AddRoleHandModel viewModel)
  42. {
  43. var del = await _repository.DeleteByRoleIdAsync(viewModel.C_RoleCode);
  44. if (viewModel.HandList != null && viewModel.HandList.Count > 0)
  45. {
  46. foreach (var item in viewModel.HandList)
  47. {
  48. TSYS_RoleHand entity = new TSYS_RoleHand()
  49. {
  50. C_RoleCode = viewModel.C_RoleCode,
  51. C_HandCode = item,
  52. C_CreateBy = _claims.ApiUserId,
  53. D_CreateOn = DateTime.Now,
  54. };
  55. await _repository.CreateRoleHandAsync(entity);
  56. }
  57. var result = await _repository.SaveAsync();
  58. if (!result)
  59. {
  60. throw new Exception("创建失败");
  61. }
  62. }
  63. else
  64. {
  65. if (!del)
  66. {
  67. throw new Exception("删除失败");
  68. }
  69. }
  70. }
  71. public async Task DeleteRoleHandAsync(Guid handCode,Guid roleCode)
  72. {
  73. var items = await _repository.GetByConditionAsync(x=>x.C_RoleCode==roleCode&&x.C_HandCode==handCode);
  74. var content = items.FirstOrDefault();
  75. if (content == null)
  76. {
  77. throw new Exception("没有此数据");
  78. }
  79. var result = await _repository.DeleteRoleHandAsync(roleCode, handCode);
  80. if (!result)
  81. {
  82. throw new Exception("删除失败");
  83. }
  84. }
  85. public async Task<IEnumerable<TSYSRoleHandModel>> GetRoleHandListAsync(Guid roleId)
  86. {
  87. var result = await _repository.GetList(roleId);
  88. return result;
  89. }
  90. public Task DeleteAsync(Guid id)
  91. {
  92. throw new NotImplementedException();
  93. }
  94. public Task<TSYSRoleHandViewModel> GetByIdAsync(Guid id)
  95. {
  96. throw new NotImplementedException();
  97. }
  98. public Task<bool> IsExistAsync(Guid id)
  99. {
  100. throw new NotImplementedException();
  101. }
  102. public Task<int> UpdateOneAsync(TSYSRoleHandViewModel viewModel, params string[] fields)
  103. {
  104. throw new NotImplementedException();
  105. }
  106. }
  107. }