TispContentGroupService.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using AutoMapper;
  2. using Ropin.Inspection.Common.Accessor.Interface;
  3. using Ropin.Inspection.Model.Entities;
  4. using Ropin.Inspection.Model.SearchModel;
  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.Text;
  12. using System.Threading.Tasks;
  13. namespace Ropin.Inspection.Service
  14. {
  15. public class TispContentGroupService : ITispContentGroupService
  16. {
  17. private readonly ITispContentGroupRepository _repository;
  18. private readonly IMapper _mapper;
  19. private readonly IClaimsAccessor _claims;
  20. public TispContentGroupService(IClaimsAccessor claims, ITispContentGroupRepository repository, IMapper mapper)
  21. {
  22. _repository = repository;
  23. _mapper = mapper;
  24. _claims = claims;
  25. }
  26. public async Task<IEnumerable<TispContentGroupViewModel>> GetAllAsync()
  27. {
  28. var pagedList = await _repository.GetAllAsync();
  29. var contentDtoList = _mapper.Map<IEnumerable<TispContentGroupViewModel>>(pagedList);
  30. return contentDtoList.ToList();
  31. }
  32. public async Task<IEnumerable<TispContentGroupViewModel>> GetContentGroupsAsync(TispContentGroupsSearchModel searchModel)
  33. {
  34. var pagedList = await _repository.GetAllAsync();
  35. var contentDtoList = _mapper.Map<IEnumerable<TispContentGroupViewModel>>(pagedList.Where(i => i.C_StoreCode == searchModel.C_StoreCode)).OrderBy(t=>t.I_Sort);
  36. if (!string.IsNullOrEmpty(searchModel.C_Name))
  37. {
  38. return contentDtoList.Where(i=>i.C_Name.Contains(searchModel.C_Name)).ToList();
  39. }
  40. return contentDtoList.ToList();
  41. }
  42. public async Task CreateOneAsync(TispContentGroupViewModel viewModel)
  43. {
  44. var content = _mapper.Map<TISP_ContentGroup>(viewModel);
  45. content.G_ID = Guid.NewGuid();
  46. content.G_CreateBy = _claims.ApiUserId;
  47. content.D_CreateOn = DateTime.Now;
  48. content.C_Status = "1";
  49. _repository.Create(content);
  50. var result = await _repository.SaveAsync();
  51. if (!result)
  52. {
  53. throw new Exception("创建失败");
  54. }
  55. }
  56. public async Task DeleteAsync(Guid id)
  57. {
  58. var content = await _repository.GetByIdAsync(id);
  59. if (content == null)
  60. {
  61. throw new Exception("没有此巡检内容分组");
  62. }
  63. content.G_LastUpdatedBy = _claims.ApiUserId;
  64. content.D_LastUpdatedOn = DateTime.Now;
  65. content.C_Status = "0";
  66. _repository.Update(content);
  67. var result = await _repository.SaveAsync();
  68. //_repository.delete(content);
  69. //var result = await _repository.saveasync();
  70. if (!result)
  71. {
  72. throw new Exception("删除失败");
  73. }
  74. }
  75. public Task<TispContentGroupViewModel> GetByIdAsync(Guid id)
  76. {
  77. throw new NotImplementedException();
  78. }
  79. public Task<bool> IsExistAsync(Guid id)
  80. {
  81. throw new NotImplementedException();
  82. }
  83. public Task<int> UpdateOneAsync(TispContentUpdateGroupViewModel viewModel, params string[] fields)
  84. {
  85. throw new NotImplementedException();
  86. }
  87. public async Task UpdateAsync(Guid id, TispContentUpdateGroupViewModel updateModel)
  88. {
  89. var content = await _repository.GetByIdAsync(id);
  90. if (content == null)
  91. {
  92. throw new Exception("没有此巡检内容分组");
  93. }
  94. content.G_LastUpdatedBy = _claims.ApiUserId;
  95. content.D_LastUpdatedOn = DateTime.Now;
  96. _mapper.Map(updateModel, content, typeof(TispContentUpdateGroupViewModel), typeof(TISP_ContentGroup));
  97. _repository.Update(content);
  98. var result = await _repository.SaveAsync();
  99. if (!result)
  100. {
  101. throw new Exception("更新失败");
  102. }
  103. }
  104. public Task<int> UpdateOneAsync(TispContentGroupViewModel viewModel, params string[] fields)
  105. {
  106. throw new NotImplementedException();
  107. }
  108. }
  109. }