123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using AutoMapper;
- using Datory;
- using GxPress.Common.AppOptions;
- using GxPress.Common.Tools;
- using GxPress.Repository.Interface.Media;
- using GxPress.Result.Media;
- using Microsoft.Extensions.Options;
- namespace GxPress.Repository.Implement.Media
- {
- public class MediaLibraryRepository : IMediaLibraryRepository
- {
- private readonly Repository<Entity.tede2.Media.MediaLibrary> _repository;
- private readonly IMapper _mapper;
- private readonly string _connectionString;
- private readonly string _databaseTypestr;
- public MediaLibraryRepository(IOptionsMonitor<DatabaseOptions> dbOptionsAccessor, IMapper mapper)
- {
- _databaseTypestr = dbOptionsAccessor.CurrentValue.DatabaseType;
- _connectionString = dbOptionsAccessor.CurrentValue.ConnectionString;
- var databaseType =
- StringUtils.ToEnum<DatabaseType>(dbOptionsAccessor.CurrentValue.DatabaseType, DatabaseType.MySql);
- var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
- _repository = new Repository<Entity.tede2.Media.MediaLibrary>(database);
- _mapper = mapper;
- }
- public IDatabase Database => _repository.Database;
- public string TableName => _repository.TableName;
- public List<TableColumn> TableColumns => _repository.TableColumns;
- public async Task<Entity.tede2.Media.MediaLibrary> GetTaskAsync(int mediaId)
- {
- return await _repository.GetAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), mediaId).Where(nameof(Entity.tede2.Media.MediaLibrary.TypeId), 1));
- }
- public async Task<Entity.tede2.Media.MediaLibrary> GetAsync(int id)
- {
- return await _repository.GetAsync(id);
- }
- /// <summary>
- /// 获取视频
- /// </summary>
- /// <param name="mediaId"></param>
- /// <param name="TypeId"></param>
- /// <returns></returns>
- public async Task<List<MediaLibraryResult>> GetAllAsync(int mediaId)
- {
- var result = await _repository.GetAllAsync(Q.Select(nameof(Entity.tede2.Media.MediaLibrary.Id), nameof(Entity.tede2.Media.MediaLibrary.Name), nameof(Entity.tede2.Media.MediaLibrary.MediaId)).Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), mediaId).Where(nameof(Entity.tede2.Media.MediaLibrary.TypeId), 2));
- return result.Select(n => _mapper.Map<MediaLibraryResult>(n)).ToList();
- }
- }
- }
|