TispSpotContentService.cs 4.3 KB

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