TispContentGroupItemService.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.Text;
  11. using System.Threading.Tasks;
  12. namespace Ropin.Inspection.Service
  13. {
  14. public class TispContentGroupItemService : ITispContentGroupItemService
  15. {
  16. private readonly ITispContentGroupItemRepository _repository;
  17. private readonly IMapper _mapper;
  18. private readonly IClaimsAccessor _claims;
  19. public TispContentGroupItemService(IClaimsAccessor claims, ITispContentGroupItemRepository repository, IMapper mapper)
  20. {
  21. _repository = repository;
  22. _mapper = mapper;
  23. _claims = claims;
  24. }
  25. public async Task CreateContentGroupItemsAsync(IEnumerable<TispContentGroupItemCreateViewModel> items)
  26. {
  27. foreach (var item in items)
  28. {
  29. await _repository.DeleteByGroupIdAsync(item.G_ContentGroupCode);
  30. _repository.Create(new TISP_ContentGroupItem { G_ContentGroupCode = item.G_ContentGroupCode,G_ContentCode = item.G_ContentCode });
  31. }
  32. var result = await _repository.SaveAsync();
  33. if (!result)
  34. {
  35. throw new Exception("创建失败");
  36. }
  37. }
  38. public async Task<IEnumerable<TispContentGroupItemViewModel>> GetContentGroupItemByGroupIdAsync(Guid groupId)
  39. {
  40. return await _repository.GetContentGroupItemByGroupIdAsync(groupId);
  41. }
  42. public async Task CreateOneAsync(TispContentGroupItemViewModel viewModel)
  43. {
  44. var content = _mapper.Map<TISP_ContentGroupItem>(viewModel);
  45. //content.G_CreateBy = _claims.ApiUserId;
  46. //content.D_CreateOn = DateTime.Now;
  47. //content.C_Status = "1";
  48. _repository.Create(content);
  49. var result = await _repository.SaveAsync();
  50. if (!result)
  51. {
  52. throw new Exception("创建失败");
  53. }
  54. }
  55. public async Task DeleteAsync(Guid id)
  56. {
  57. var content = await _repository.GetByIdAsync(id);
  58. if (content == null)
  59. {
  60. throw new Exception("没有此巡检内容分组详情");
  61. }
  62. _repository.Delete(content);
  63. var result = await _repository.SaveAsync();
  64. if (!result)
  65. {
  66. throw new Exception("删除失败");
  67. }
  68. }
  69. public Task<IEnumerable<TispContentGroupItemViewModel>> GetAllAsync()
  70. {
  71. throw new NotImplementedException();
  72. }
  73. public Task<TispContentGroupItemViewModel> GetByIdAsync(Guid id)
  74. {
  75. throw new NotImplementedException();
  76. }
  77. public Task<bool> IsExistAsync(Guid id)
  78. {
  79. throw new NotImplementedException();
  80. }
  81. public Task<int> UpdateOneAsync(TispContentGroupItemViewModel viewModel, params string[] fields)
  82. {
  83. throw new NotImplementedException();
  84. }
  85. }
  86. }