TsysRoleHandServices.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. }
  64. public async Task DeleteRoleHandAsync(Guid handCode,Guid roleCode)
  65. {
  66. var items = await _repository.GetByConditionAsync(x=>x.C_RoleCode==roleCode&&x.C_HandCode==handCode);
  67. var content = items.FirstOrDefault();
  68. if (content == null)
  69. {
  70. throw new Exception("没有此数据");
  71. }
  72. var result = await _repository.DeleteRoleHandAsync(roleCode, handCode);
  73. if (!result)
  74. {
  75. throw new Exception("删除失败");
  76. }
  77. }
  78. public async Task<IEnumerable<TSYSRoleHandModel>> GetRoleHandListAsync(Guid roleId)
  79. {
  80. var result = await _repository.GetList(roleId);
  81. return result;
  82. }
  83. public Task DeleteAsync(Guid id)
  84. {
  85. throw new NotImplementedException();
  86. }
  87. public Task<TSYSRoleHandViewModel> GetByIdAsync(Guid id)
  88. {
  89. throw new NotImplementedException();
  90. }
  91. public Task<bool> IsExistAsync(Guid id)
  92. {
  93. throw new NotImplementedException();
  94. }
  95. public Task<int> UpdateOneAsync(TSYSRoleHandViewModel viewModel, params string[] fields)
  96. {
  97. throw new NotImplementedException();
  98. }
  99. }
  100. }