TispContentGroupService.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. var contentDtoList = await _repository.GetList(searchModel);
  41. return contentDtoList;
  42. }
  43. public async Task CreateOneAsync(TispContentGroupViewModel viewModel)
  44. {
  45. var content = _mapper.Map<TISP_ContentGroup>(viewModel);
  46. content.G_ID = Guid.NewGuid();
  47. content.G_CreateBy = _claims.ApiUserId;
  48. content.D_CreateOn = DateTime.Now;
  49. content.C_Status = "1";
  50. _repository.Create(content);
  51. var result = await _repository.SaveAsync();
  52. if (!result)
  53. {
  54. throw new Exception("创建失败");
  55. }
  56. }
  57. public async Task DeleteAsync(Guid id)
  58. {
  59. var content = await _repository.GetByIdAsync(id);
  60. if (content == null)
  61. {
  62. throw new Exception("没有此巡检内容分组");
  63. }
  64. content.G_LastUpdatedBy = _claims.ApiUserId;
  65. content.D_LastUpdatedOn = DateTime.Now;
  66. content.C_Status = "0";
  67. _repository.Update(content);
  68. var result = await _repository.SaveAsync();
  69. //_repository.delete(content);
  70. //var result = await _repository.saveasync();
  71. if (!result)
  72. {
  73. throw new Exception("删除失败");
  74. }
  75. }
  76. public Task<TispContentGroupViewModel> GetByIdAsync(Guid id)
  77. {
  78. throw new NotImplementedException();
  79. }
  80. public Task<bool> IsExistAsync(Guid id)
  81. {
  82. throw new NotImplementedException();
  83. }
  84. public Task<int> UpdateOneAsync(TispContentUpdateGroupViewModel viewModel, params string[] fields)
  85. {
  86. throw new NotImplementedException();
  87. }
  88. public async Task UpdateAsync(Guid id, TispContentUpdateGroupViewModel updateModel)
  89. {
  90. var content = await _repository.GetByIdAsync(id);
  91. if (content == null)
  92. {
  93. throw new Exception("没有此巡检内容分组");
  94. }
  95. content.G_LastUpdatedBy = _claims.ApiUserId;
  96. content.D_LastUpdatedOn = DateTime.Now;
  97. _mapper.Map(updateModel, content, typeof(TispContentUpdateGroupViewModel), typeof(TISP_ContentGroup));
  98. _repository.Update(content);
  99. var result = await _repository.SaveAsync();
  100. if (!result)
  101. {
  102. throw new Exception("更新失败");
  103. }
  104. }
  105. public Task<int> UpdateOneAsync(TispContentGroupViewModel viewModel, params string[] fields)
  106. {
  107. throw new NotImplementedException();
  108. }
  109. }
  110. }