MiddleLableRepository.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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.Navigations;
  8. using GxPress.Repository.Interface.Navigation;
  9. using Microsoft.Extensions.Options;
  10. namespace GxPress.Repository.Implement.Navigation
  11. {
  12. public class MiddleLableRepository :IMiddleLableRepository
  13. {
  14. private readonly Repository<Entity.Navigations.MiddleLable> _repository;
  15. private readonly IMapper _mapper;
  16. private readonly string _connectionString;
  17. private readonly string _databaseTypestr;
  18. public MiddleLableRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
  19. {
  20. _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
  21. _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
  22. var databaseType =
  23. StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
  24. var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
  25. _repository = new Repository<Entity.Navigations.MiddleLable>(database);
  26. _mapper = mapper;
  27. }
  28. public IDatabase Database => _repository.Database;
  29. public string TableName => _repository.TableName;
  30. public List<TableColumn> TableColumns => _repository.TableColumns;
  31. public async Task<Entity.Navigations.MiddleLable> GetAsync(int id)
  32. {
  33. return await _repository.GetAsync(id);
  34. }
  35. public async Task<bool> DeleteAsync(int id)
  36. {
  37. return await _repository.DeleteAsync(id);
  38. }
  39. public async Task<int> InsertAsync(Entity.Navigations.MiddleLable note)
  40. {
  41. return await _repository.InsertAsync(note);
  42. }
  43. public async Task<bool> UpdateAsync(Entity.Navigations.MiddleLable note)
  44. {
  45. return await _repository.UpdateAsync(note);
  46. }
  47. public async Task<bool> UpdateAsync(SqlKata.Query query)
  48. {
  49. return await _repository.UpdateAsync(query) > 0;
  50. }
  51. public async Task<IEnumerable<Entity.Navigations.MiddleLable>> GetAllAsync()
  52. {
  53. return await _repository.GetAllAsync(Q.Where(nameof(Entity.Navigations.MiddleLable.IsDisable), false).OrderByDesc(nameof(Entity.Navigations.MiddleLable.Sort)));
  54. }
  55. }
  56. }