12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 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 selectColumn = new List<string>();
- selectColumn.Add(nameof(Entity.tede2.Media.MediaLibrary.Id));
- selectColumn.Add(nameof(Entity.tede2.Media.MediaLibrary.Name));
- selectColumn.Add(nameof(Entity.tede2.Media.MediaLibrary.MediaId));
- var result = await _repository.GetAllAsync<MediaLibraryResult>(Q.Select(selectColumn.ToArray()).Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), mediaId).Where(nameof(Entity.tede2.Media.MediaLibrary.TypeId), 0));
- return result.Select(n => _mapper.Map<MediaLibraryResult>(n)).ToList();
- }
- }
- }
|