MediaLableRepository.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.Media;
  8. using Microsoft.Extensions.Options;
  9. namespace GxPress.Repository.Implement.Media
  10. {
  11. public class MediaLableRepository : IMediaLableRepository
  12. {
  13. private readonly Repository<Entity.tede2.Media.MediaLable> _repository;
  14. private readonly IMapper _mapper;
  15. private readonly string _connectionString;
  16. private readonly string _databaseTypestr;
  17. public MediaLableRepository(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.tede2.Media.MediaLable>(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<IEnumerable<int>> GetMediaIdsAysnc(int lableId)
  31. {
  32. return await _repository.GetAllAsync<int>(Q.Select(nameof(Entity.tede2.Media.MediaLable.MediaId)).Where(nameof(Entity.tede2.Media.MediaLable.LableId), lableId));
  33. }
  34. }
  35. }