LGSLargeScreenService.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using AutoMapper;
  2. using Ropin.Inspection.Common.Accessor.Interface;
  3. using Ropin.Inspection.Model.Entities;
  4. using Ropin.Inspection.Model.SearchModel.LGS;
  5. using Ropin.Inspection.Model.ViewModel.LGS;
  6. using Ropin.Inspection.Repository.LGS.Interface;
  7. using Ropin.Inspection.Service.LGS.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.LGS
  14. {
  15. public class LGSLargeScreenService : ILGSLargeScreenService
  16. {
  17. private readonly ILGSLargeScreenRepository _repository;
  18. private readonly IMapper _mapper;
  19. private readonly IClaimsAccessor _claims;
  20. private readonly InspectionDbContext _sqlDBContext;
  21. public LGSLargeScreenService(IClaimsAccessor claims, InspectionDbContext sqlDBContext, ILGSLargeScreenRepository repository, IMapper mapper)
  22. {
  23. _repository = repository;
  24. _mapper = mapper;
  25. _claims = claims;
  26. _sqlDBContext = sqlDBContext;
  27. }
  28. public async Task<IEnumerable<LargeScreenViewModel>> GetConditionAsync(LargeScreenSearch searchModel)
  29. {
  30. var list = await _repository.GetConditionAsync(searchModel);
  31. return list;
  32. }
  33. public async Task CreateOneAsync(LargeScreenViewModel viewModel)
  34. {
  35. var content = _mapper.Map<TLGS_LargeScreen>(viewModel);
  36. content.C_ID = Guid.NewGuid().ToString();
  37. content.C_CreateBy = _claims.ApiUserId.ToString();
  38. content.C_Creator = _claims.ApiUserName;
  39. content.D_CreateOn = DateTime.Now;
  40. content.C_Status = "1";
  41. _repository.Create(content);
  42. var result = await _repository.SaveAsync();
  43. if (!result)
  44. {
  45. throw new Exception("创建失败");
  46. }
  47. }
  48. public async Task DeleteAsync(string id)
  49. {
  50. var content = await _repository.GetByIdAsync(id);
  51. if (content == null)
  52. {
  53. throw new Exception("数据库中没有此数据");
  54. }
  55. content.C_LastUpdatedBy = _claims.ApiUserId.ToString();
  56. content.D_LastUpdatedOn = DateTime.Now;
  57. content.C_Modifier = _claims.ApiUserName;
  58. content.C_Status = "0";
  59. _repository.Update(content);
  60. var result = await _repository.SaveAsync();
  61. if (!result)
  62. {
  63. throw new Exception("删除失败");
  64. }
  65. }
  66. public async Task<LargeScreenViewModel> GetByIdAsync(string id)
  67. {
  68. LargeScreenSearch searchModel = new LargeScreenSearch();
  69. searchModel.IsPagination = false;
  70. searchModel.C_ID = id;
  71. var list = await _repository.GetConditionAsync(searchModel);
  72. return list?.FirstOrDefault();
  73. }
  74. public async Task UpdateAsync(LargeScreenViewModel viewModel, string Id)
  75. {
  76. var content = await _repository.GetByIdAsync(Id);
  77. if (content == null)
  78. {
  79. throw new Exception("没有此数据");
  80. }
  81. _mapper.Map(viewModel, content, typeof(LargeScreenViewModel), typeof(TLGS_LargeScreen));
  82. content.C_LastUpdatedBy = _claims.Linsence == null ? _claims.ApiUserId.ToString() : "6e864cbc-5252-11ec-8681-fa163e02b3e4";
  83. content.D_LastUpdatedOn = DateTime.Now;
  84. content.C_Modifier = _claims.ApiUserName;
  85. _repository.Update(content);
  86. var result = await _repository.SaveAsync();
  87. if (!result)
  88. {
  89. throw new Exception("更新失败");
  90. }
  91. }
  92. public Task<bool> IsExistAsync(string id)
  93. {
  94. throw new NotImplementedException();
  95. }
  96. public Task<int> UpdateOneAsync(LargeScreenViewModel viewModel, params string[] fields)
  97. {
  98. throw new NotImplementedException();
  99. }
  100. }
  101. }