dev_DevBoxMigrateService.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using AutoMapper;
  2. using Ropin.Inspection.Common.Accessor.Interface;
  3. using Ropin.Inspection.Model;
  4. using Ropin.Inspection.Model.Entities;
  5. using Ropin.Inspection.Model.ViewModel.DEV;
  6. using Ropin.Inspection.Repository;
  7. using Ropin.Inspection.Repository.DEV.Interface;
  8. using Ropin.Inspection.Service.DEV.Interface;
  9. using System;
  10. using System.Collections.Generic;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. namespace Ropin.Inspection.Service.DEV
  15. {
  16. public class dev_DevBoxMigrateService : Idev_DevBoxMigrateService
  17. {
  18. private readonly Idev_DevBoxMigrateRepository _repository;
  19. private readonly IMapper _mapper;
  20. private readonly IClaimsAccessor _claims;
  21. private readonly InspectionDbContext _sqlDBContext;
  22. private readonly ITdevBoxRepository _tdevBoxRepository;
  23. public dev_DevBoxMigrateService(IClaimsAccessor claims, InspectionDbContext sqlDBContext, Idev_DevBoxMigrateRepository repository, IMapper mapper, ITdevBoxRepository tdevBoxRepository)
  24. {
  25. _repository = repository;
  26. _mapper = mapper;
  27. _claims = claims;
  28. _sqlDBContext = sqlDBContext;
  29. _tdevBoxRepository= tdevBoxRepository;
  30. }
  31. public async Task CreateOneAsync(dev_DevBoxMigrateModel viewModel)
  32. {
  33. viewModel.C_ID = Guid.NewGuid().ToString();
  34. var content = _mapper.Map<TDEV_DevBoxMigrate>(viewModel);
  35. var devStore = await _tdevBoxRepository.GetByIdAsync(viewModel.C_DevBoxCode);
  36. if (devStore == null)
  37. {
  38. throw new Exception("创建失败,没有找到要移机的盒子");
  39. }
  40. devStore.C_StoreCode = viewModel.C_CurrentStoreCode;
  41. _tdevBoxRepository.Update(devStore);
  42. //content.C_ID = id;
  43. content.C_CreateBy = _claims.ApiUserId;
  44. content.D_CreateOn = DateTime.Now;
  45. _repository.Create(content);
  46. var result = await _repository.SaveAsync();
  47. if (!result)
  48. {
  49. throw new Exception("创建失败");
  50. }
  51. }
  52. public async Task<IEnumerable<dev_DevBoxMigrateModel>> GetConditionAsync(dev_DevBoxMigrateSearchModel searchModel)
  53. {
  54. var dtoList = await _repository.GetConditionAsync(searchModel);
  55. return dtoList;
  56. }
  57. public Task DeleteAsync(string id)
  58. {
  59. throw new NotImplementedException();
  60. }
  61. public Task<dev_DevBoxMigrateModel> GetByIdAsync(string id)
  62. {
  63. throw new NotImplementedException();
  64. }
  65. public Task<bool> IsExistAsync(string id)
  66. {
  67. throw new NotImplementedException();
  68. }
  69. public Task<int> UpdateOneAsync(dev_DevBoxMigrateModel viewModel, params string[] fields)
  70. {
  71. throw new NotImplementedException();
  72. }
  73. }
  74. }