WaitHandleLabelRepository.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections.Generic;
  2. using System.Threading.Tasks;
  3. using AutoMapper;
  4. using Datory;
  5. using GxPress.Common.AppOptions;
  6. using GxPress.Common.Tools;
  7. using GxPress.Entity.WaitHandle;
  8. using GxPress.Repository.Interface.WaitHandle;
  9. using Microsoft.Extensions.Options;
  10. using SqlKata;
  11. namespace GxPress.Repository.Implement.WaitHandle
  12. {
  13. public class WaitHandleLabelRepository: IWaitHandleLabelRepository
  14. {
  15. private readonly Repository<WaitHandleLabel> _repository;
  16. private readonly IMapper _mapper;
  17. public WaitHandleLabelRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
  18. {
  19. var databaseType = StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  20. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  21. _repository = new Repository<WaitHandleLabel>(database);
  22. _mapper = mapper;
  23. }
  24. public IDatabase Database => _repository.Database;
  25. public string TableName => _repository.TableName;
  26. public List<TableColumn> TableColumns => _repository.TableColumns;
  27. public async Task<int> InsertAsync(WaitHandleLabel waitHandleLabel)
  28. {
  29. return await _repository.InsertAsync(waitHandleLabel);
  30. }
  31. public async Task<bool> UpdateAsync(WaitHandleLabel waitHandleLabel)
  32. {
  33. return await _repository.UpdateAsync(waitHandleLabel);
  34. }
  35. public async Task<bool> UpdateAsync(Query query)
  36. {
  37. return await _repository.UpdateAsync(query)>0;
  38. }
  39. public async Task<bool> DeleteAsync(int id)
  40. {
  41. return await _repository.DeleteAsync(id);
  42. }
  43. public async Task<bool> DeleteAsync(Query query)
  44. {
  45. return await _repository.DeleteAsync(query)>0;
  46. }
  47. public async Task<WaitHandleLabel> GetAsync(Query query)
  48. {
  49. return await _repository.GetAsync(query);
  50. }
  51. public async Task<WaitHandleLabel> GetAsync(int id)
  52. {
  53. return await _repository.GetAsync(id);
  54. }
  55. public async Task<IEnumerable<WaitHandleLabel>> GetAllAsync(Query query)
  56. {
  57. return await _repository.GetAllAsync(query);
  58. }
  59. public async Task<int> CountAsync(Query query)
  60. {
  61. return await _repository.CountAsync(query);
  62. }
  63. }
  64. }