TsysRoleHandServices.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. foreach (var item in viewModel.HandList)
  45. {
  46. TSYS_RoleHand entity = new TSYS_RoleHand()
  47. {
  48. C_RoleCode = viewModel.C_RoleCode,
  49. C_HandCode = item,
  50. C_CreateBy = _claims.ApiUserId,
  51. D_CreateOn = DateTime.Now,
  52. };
  53. await _repository.CreateRoleHandAsync(entity);
  54. }
  55. var result = await _repository.SaveAsync();
  56. if (!result)
  57. {
  58. throw new Exception("创建失败");
  59. }
  60. }
  61. public async Task DeleteRoleHandAsync(Guid handCode,Guid roleCode)
  62. {
  63. var items = await _repository.GetByConditionAsync(x=>x.C_RoleCode==roleCode&&x.C_HandCode==handCode);
  64. var content = items.FirstOrDefault();
  65. if (content == null)
  66. {
  67. throw new Exception("没有此数据");
  68. }
  69. var result = await _repository.DeleteRoleHandAsync(roleCode, handCode);
  70. if (!result)
  71. {
  72. throw new Exception("删除失败");
  73. }
  74. }
  75. public async Task<IEnumerable<TSYSRoleHandModel>> GetRoleHandListAsync(Guid roleId)
  76. {
  77. var result = await _repository.GetList(roleId);
  78. return result;
  79. }
  80. public Task DeleteAsync(Guid id)
  81. {
  82. throw new NotImplementedException();
  83. }
  84. public Task<TSYSRoleHandViewModel> GetByIdAsync(Guid id)
  85. {
  86. throw new NotImplementedException();
  87. }
  88. public Task<bool> IsExistAsync(Guid id)
  89. {
  90. throw new NotImplementedException();
  91. }
  92. public Task<int> UpdateOneAsync(TSYSRoleHandViewModel viewModel, params string[] fields)
  93. {
  94. throw new NotImplementedException();
  95. }
  96. }
  97. }