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