TispContentGroupItemService.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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<IEnumerable<TISP_ContentGroupItem>> GetContentGroupItemByIdAsync(Guid groupId,Guid contentId)
  43. {
  44. var content = await _repository.GetByConditionAsync(g => g.G_ContentGroupCode == groupId && g.G_ContentCode == contentId);
  45. if (content.Count()==1&& content.First()==null)
  46. {
  47. content = null;
  48. }
  49. return content;
  50. }
  51. public async Task CreateOneAsync(TispContentGroupItemViewModel viewModel)
  52. {
  53. var content = _mapper.Map<TISP_ContentGroupItem>(viewModel);
  54. //content.G_CreateBy = _claims.ApiUserId;
  55. //content.D_CreateOn = DateTime.Now;
  56. //content.C_Status = "1";
  57. _repository.Create(content);
  58. var result = await _repository.SaveAsync();
  59. if (!result)
  60. {
  61. throw new Exception("创建失败");
  62. }
  63. }
  64. public async Task DeleteAsync(Guid id)
  65. {
  66. var content = await _repository.GetByIdAsync(id);
  67. if (content == null)
  68. {
  69. throw new Exception("没有此巡检内容分组详情");
  70. }
  71. _repository.Delete(content);
  72. var result = await _repository.SaveAsync();
  73. if (!result)
  74. {
  75. throw new Exception("删除失败");
  76. }
  77. }
  78. public Task<IEnumerable<TispContentGroupItemViewModel>> GetAllAsync()
  79. {
  80. throw new NotImplementedException();
  81. }
  82. public Task<TispContentGroupItemViewModel> GetByIdAsync(Guid id)
  83. {
  84. throw new NotImplementedException();
  85. }
  86. public Task<bool> IsExistAsync(Guid id)
  87. {
  88. throw new NotImplementedException();
  89. }
  90. public Task<int> UpdateOneAsync(TispContentGroupItemViewModel viewModel, params string[] fields)
  91. {
  92. throw new NotImplementedException();
  93. }
  94. }
  95. }