ArticleInnerLabelRepository.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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.ArticleLabel;
  8. using GxPress.Repository.Interface.ArticleLabel;
  9. using Microsoft.Extensions.Options;
  10. using SqlKata;
  11. namespace GxPress.Repository.Implement.ArticleLabel
  12. {
  13. public class ArticleInnerLabelRepository : IArticleInnerLabelRepository
  14. {
  15. private readonly Repository<Entity.ArticleLabel.ArticleInnerLabel> _repository;
  16. private readonly IMapper _mapper;
  17. public ArticleInnerLabelRepository(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<Entity.ArticleLabel.ArticleInnerLabel>(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<bool> DeleteAsync(Query query)
  28. {
  29. return await _repository.DeleteAsync(query) > 0;
  30. }
  31. public async Task<IEnumerable<ArticleInnerLabel>> GetAllAsync(Query query)
  32. {
  33. return await _repository.GetAllAsync(query);
  34. }
  35. public async Task<ArticleInnerLabel> GetAsync(int id)
  36. {
  37. return await _repository.GetAsync(id);
  38. }
  39. public async Task<int> InsertAsync(ArticleInnerLabel articleInnerLabel)
  40. {
  41. return await _repository.InsertAsync(articleInnerLabel);
  42. }
  43. public async Task<bool> UpdateAsync(ArticleInnerLabel articleInnerLabel)
  44. {
  45. return await _repository.UpdateAsync(articleInnerLabel);
  46. }
  47. public async Task<bool> UpdateAsync(Query query)
  48. {
  49. return await _repository.UpdateAsync(query) > 0;
  50. }
  51. }
  52. }