|
@@ -9,6 +9,7 @@ using GxPress.Repository.Interface.Media;
|
|
|
using GxPress.Result.Media;
|
|
|
using Microsoft.Extensions.Options;
|
|
|
using System.Transactions;
|
|
|
+using GxPress.Common.Exceptions;
|
|
|
|
|
|
namespace GxPress.Repository.Implement.Media
|
|
|
{
|
|
@@ -16,6 +17,7 @@ namespace GxPress.Repository.Implement.Media
|
|
|
{
|
|
|
private readonly Repository<Entity.tede2.Media.Media> _repository;
|
|
|
private readonly Repository<Entity.tede2.Media.MediaLibrary> mediaLibraryRepository;
|
|
|
+ private readonly Repository<Entity.tede2.Media.MediaLable> mediaLableRepository;
|
|
|
private readonly IMapper _mapper;
|
|
|
private readonly string _connectionString;
|
|
|
private readonly string _databaseTypestr;
|
|
@@ -28,6 +30,7 @@ namespace GxPress.Repository.Implement.Media
|
|
|
var database = new Database(databaseType, dbOptionsAccessor.CurrentValue.ConnectionString);
|
|
|
_repository = new Repository<Entity.tede2.Media.Media>(database);
|
|
|
mediaLibraryRepository = new Repository<Entity.tede2.Media.MediaLibrary>(database);
|
|
|
+ mediaLableRepository = new Repository<Entity.tede2.Media.MediaLable>(database);
|
|
|
_mapper = mapper;
|
|
|
}
|
|
|
|
|
@@ -43,13 +46,36 @@ namespace GxPress.Repository.Implement.Media
|
|
|
result = _mapper.Map<MediaResult>(media);
|
|
|
//获取媒体库资源
|
|
|
var mediaLibrarys = await mediaLibraryRepository.GetAllAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), id));
|
|
|
- result.MediaLibraryRequest = mediaLibrarys.ToList().Select(n => _mapper.Map<MediaLibraryResult>(n)).ToList();
|
|
|
+ result.MediaLibraryResults = mediaLibrarys.ToList().Select(n => _mapper.Map<MediaLibraryResult>(n)).ToList();
|
|
|
+ //获取媒体标签
|
|
|
+ var mediaLables = await mediaLableRepository.GetAllAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), id));
|
|
|
+ result.MediaLableResults = mediaLables.Select(n => _mapper.Map<MediaLableResult>(n)).ToList();
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
+ /// <summary>
|
|
|
+ /// 删除媒体
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="id"></param>
|
|
|
+ /// <returns></returns>
|
|
|
public async Task<bool> DeleteAsync(int id)
|
|
|
{
|
|
|
- return await _repository.DeleteAsync(id);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var transactionScope = new TransactionScope())
|
|
|
+ {
|
|
|
+ //删除媒体库
|
|
|
+ await mediaLibraryRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), id));
|
|
|
+ //删除媒体标签
|
|
|
+ await mediaLableRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), id));
|
|
|
+ await _repository.DeleteAsync(id);
|
|
|
+ transactionScope.Complete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (System.Exception ex)
|
|
|
+ {
|
|
|
+ throw new BusinessException(ex.Message);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 添加媒体
|
|
@@ -66,15 +92,22 @@ namespace GxPress.Repository.Implement.Media
|
|
|
var id = await _repository.InsertAsync(model);
|
|
|
if (id > 0)
|
|
|
{
|
|
|
- foreach (var item in result.MediaLibraryRequest)
|
|
|
+ foreach (var item in result.MediaLibraryResults)
|
|
|
{
|
|
|
var mediaLibrary = _mapper.Map<Entity.tede2.Media.MediaLibrary>(item);
|
|
|
await mediaLibraryRepository.InsertAsync(mediaLibrary);
|
|
|
}
|
|
|
}
|
|
|
- if(result.Id==0&&result.TeacherId==0&&!string.IsNullOrEmpty(result.Author)){
|
|
|
+ //添加标签
|
|
|
+ foreach (var item in result.MediaLableResults)
|
|
|
+ {
|
|
|
+ var mediaLable = _mapper.Map<Entity.tede2.Media.MediaLable>(item);
|
|
|
+ await mediaLableRepository.InsertAsync(mediaLable);
|
|
|
+ }
|
|
|
+ if (result.Id == 0 && result.TeacherId == 0 && !string.IsNullOrEmpty(result.Author))
|
|
|
+ {
|
|
|
//新增名师
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
//提交事务
|
|
|
transactionScope.Complete();
|
|
@@ -112,11 +145,19 @@ namespace GxPress.Repository.Implement.Media
|
|
|
await _repository.UpdateAsync(model);
|
|
|
//删除媒体库
|
|
|
await mediaLibraryRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), result.Id));
|
|
|
- foreach (var item in result.MediaLibraryRequest)
|
|
|
+ //删除媒体标签
|
|
|
+ await mediaLableRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLable.MediaId), result.Id));
|
|
|
+ foreach (var item in result.MediaLibraryResults)
|
|
|
{
|
|
|
var mediaLibrary = _mapper.Map<Entity.tede2.Media.MediaLibrary>(item);
|
|
|
await mediaLibraryRepository.InsertAsync(mediaLibrary);
|
|
|
}
|
|
|
+ //添加标签
|
|
|
+ foreach (var item in result.MediaLableResults)
|
|
|
+ {
|
|
|
+ var mediaLable = _mapper.Map<Entity.tede2.Media.MediaLable>(item);
|
|
|
+ await mediaLableRepository.InsertAsync(mediaLable);
|
|
|
+ }
|
|
|
//提交事务
|
|
|
transactionScope.Complete();
|
|
|
}
|