TsysUserPostService.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 TsysUserPostService : ITsysUserPostService
  15. {
  16. private readonly ITsysUserPostRepository _repository;
  17. private readonly IMapper _mapper;
  18. private readonly IClaimsAccessor _claims;
  19. public TsysUserPostService(IClaimsAccessor claims, ITsysUserPostRepository repository, IMapper mapper)
  20. {
  21. _claims = claims;
  22. _repository = repository;
  23. _mapper = mapper;
  24. }
  25. public async Task CreateOneAsync(TsysUserPostViewModel viewModel)
  26. {
  27. await _repository.DeleteByUserAsync(viewModel.G_UserCode);
  28. var content = _mapper.Map<TSYS_UserPost>(viewModel);
  29. content.G_ID = Guid.NewGuid();
  30. content.G_CreateBy = _claims.ApiUserId;
  31. content.D_CreateOn = DateTime.Now;
  32. _repository.Create(content);
  33. var result = await _repository.SaveAsync();
  34. if (!result)
  35. {
  36. throw new Exception("创建失败");
  37. }
  38. }
  39. public async Task DeleteAsync(Guid id)
  40. {
  41. var content = await _repository.GetByIdAsync(id);
  42. if (content == null)
  43. {
  44. throw new Exception("没有数据");
  45. }
  46. _repository.Delete(content);
  47. var result = await _repository.SaveAsync();
  48. if (!result)
  49. {
  50. throw new Exception("删除失败");
  51. }
  52. }
  53. public async Task<TsysUserPostViewModel> GetByIdAsync(Guid id)
  54. {
  55. var content = await _repository.GetByIdAsync(id);
  56. var contentDto = _mapper.Map<TsysUserPostViewModel>(content);
  57. return contentDto;
  58. }
  59. public async Task<TsysUserPostViewModel> GetUserPostsByUserIdAsync(Guid id)
  60. {
  61. var content = await _repository.GetUserPostsByUserIdAsync(id);
  62. var contentDto = _mapper.Map<TsysUserPostViewModel>(content);
  63. return contentDto;
  64. }
  65. public Task<bool> IsExistAsync(Guid id)
  66. {
  67. throw new NotImplementedException();
  68. }
  69. public Task<int> UpdateOneAsync(TsysUserPostViewModel viewModel, params string[] fields)
  70. {
  71. throw new NotImplementedException();
  72. }
  73. }
  74. }