TsecRecordService.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using AutoMapper;
  2. using Ropin.Inspection.Common.Accessor.Interface;
  3. using Ropin.Inspection.Model.Entities;
  4. using Ropin.Inspection.Model.ViewModel;
  5. using Ropin.Inspection.Repository.Interface;
  6. using Ropin.Inspection.Service.Interface;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Linq.Expressions;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. namespace Ropin.Inspection.Service
  14. {
  15. public class TsecRecordService : ITsecRecordService
  16. {
  17. private readonly ITsecRecordRepository _repository;
  18. private readonly IMapper _mapper;
  19. private readonly IClaimsAccessor _claims;
  20. public TsecRecordService(IClaimsAccessor claims, ITsecRecordRepository repository, IMapper mapper)
  21. {
  22. _repository = repository;
  23. _mapper = mapper;
  24. _claims = claims;
  25. }
  26. public async Task CreateOneAsync(TsecRecordViewModel viewModel)
  27. {
  28. var content = _mapper.Map<TSEC_Record>(viewModel);
  29. content.C_CreateBy = _claims.ApiUserId;
  30. content.D_CreateOn = DateTime.Now;
  31. content.C_LastUpdatedBy = _claims.ApiUserId;
  32. content.D_LastUpdatedOn = DateTime.Now;
  33. _repository.Create(content);
  34. var result = await _repository.SaveAsync();
  35. if (!result)
  36. {
  37. throw new Exception("创建失败");
  38. }
  39. }
  40. public async Task DeleteAsync(Guid id)
  41. {
  42. var content = await _repository.GetByIdAsync(id);
  43. if (content == null)
  44. {
  45. throw new Exception("没有此安检记录");
  46. }
  47. _repository.Delete(content);
  48. var result = await _repository.SaveAsync();
  49. if (!result)
  50. {
  51. throw new Exception("删除失败");
  52. }
  53. }
  54. public async Task<IEnumerable<TsecRecordViewModel>> GetAllAsync()
  55. {
  56. var pagedList = await _repository.GetAllAsync();
  57. var contentDtoList = _mapper.Map<IEnumerable<TsecRecordViewModel>>(pagedList);
  58. return contentDtoList.ToList();
  59. }
  60. public Task<IEnumerable<TsecRecordViewModel>> GetByConditionAsync(Expression<Func<TsecRecordViewModel, bool>> expression)
  61. {
  62. throw new NotImplementedException();
  63. }
  64. public async Task<TsecRecordViewModel> GetByIdAsync(Guid id)
  65. {
  66. var content = await _repository.GetByIdAsync(id);
  67. var contentDto = _mapper.Map<TsecRecordViewModel>(content);
  68. return contentDto;
  69. }
  70. public Task<bool> IsExistAsync(Guid id)
  71. {
  72. throw new NotImplementedException();
  73. }
  74. public async Task UpdateAsync(Guid id, TsecRecordUpdateViewModel updateModel)
  75. {
  76. var content = await _repository.GetByIdAsync(id);
  77. if (content == null)
  78. {
  79. throw new Exception("没有此安检记录");
  80. }
  81. content.C_LastUpdatedBy = _claims.ApiUserId;
  82. content.D_LastUpdatedOn = DateTime.Now;
  83. _mapper.Map(updateModel, content, typeof(TsecRecordUpdateViewModel), typeof(TSEC_Record));
  84. _repository.Update(content);
  85. var result = await _repository.SaveAsync();
  86. if (!result)
  87. {
  88. throw new Exception("更新失败");
  89. }
  90. }
  91. public Task<int> UpdateOneAsync(TsecRecordViewModel viewModel, params string[] fields)
  92. {
  93. throw new NotImplementedException();
  94. }
  95. }
  96. }