|
@@ -12,7 +12,7 @@ using System.Transactions;
|
|
|
|
|
|
namespace GxPress.Repository.Implement.Media
|
|
|
{
|
|
|
- public class MediaRepository: IMediaRepository
|
|
|
+ public class MediaRepository : IMediaRepository
|
|
|
{
|
|
|
private readonly Repository<Entity.tede2.Media.Media> _repository;
|
|
|
private readonly Repository<Entity.tede2.Media.MediaLibrary> mediaLibraryRepository;
|
|
@@ -39,11 +39,11 @@ namespace GxPress.Repository.Implement.Media
|
|
|
{
|
|
|
var result = new MediaResult();
|
|
|
//获取媒体
|
|
|
- var media= await _repository.GetAsync(id);
|
|
|
+ var media = await _repository.GetAsync(id);
|
|
|
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();
|
|
|
+ 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();
|
|
|
return result;
|
|
|
}
|
|
|
|
|
@@ -57,8 +57,8 @@ namespace GxPress.Repository.Implement.Media
|
|
|
/// <param name="result"></param>
|
|
|
/// <returns></returns>
|
|
|
public async Task<bool> InsertAsync(MediaResult result)
|
|
|
- {
|
|
|
- var model = _mapper.Map<Entity.tede2.Media.Media>(result);
|
|
|
+ {
|
|
|
+ var model = _mapper.Map<Entity.tede2.Media.Media>(result);
|
|
|
try
|
|
|
{
|
|
|
using (var transactionScope = new TransactionScope())
|
|
@@ -69,9 +69,9 @@ namespace GxPress.Repository.Implement.Media
|
|
|
foreach (var item in result.MediaLibraryRequest)
|
|
|
{
|
|
|
var mediaLibrary = _mapper.Map<Entity.tede2.Media.MediaLibrary>(item);
|
|
|
- await mediaLibraryRepository.InsertAsync(mediaLibrary);
|
|
|
+ await mediaLibraryRepository.InsertAsync(mediaLibrary);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
//提交事务
|
|
|
transactionScope.Complete();
|
|
@@ -81,7 +81,7 @@ namespace GxPress.Repository.Implement.Media
|
|
|
{
|
|
|
throw new Common.Exceptions.BusinessException(ex.Message);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return true;
|
|
|
}
|
|
|
|
|
@@ -98,5 +98,32 @@ namespace GxPress.Repository.Implement.Media
|
|
|
{
|
|
|
return await _repository.GetAllAsync(Q.Where(nameof(Entity.tede2.Media.Media.MediaType), mediaType).OrderByDesc(nameof(Entity.tede2.Media.Media.Sort)));
|
|
|
}
|
|
|
+
|
|
|
+ public async Task<bool> UpdateAsync(MediaResult result)
|
|
|
+ {
|
|
|
+ var model = _mapper.Map<Entity.tede2.Media.Media>(result);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ using (var transactionScope = new TransactionScope())
|
|
|
+ {
|
|
|
+ await _repository.UpdateAsync(model);
|
|
|
+ //删除媒体库
|
|
|
+ await mediaLibraryRepository.DeleteAsync(Q.Where(nameof(Entity.tede2.Media.MediaLibrary.MediaId), result.Id));
|
|
|
+ foreach (var item in result.MediaLibraryRequest)
|
|
|
+ {
|
|
|
+ var mediaLibrary = _mapper.Map<Entity.tede2.Media.MediaLibrary>(item);
|
|
|
+ await mediaLibraryRepository.InsertAsync(mediaLibrary);
|
|
|
+ }
|
|
|
+ //提交事务
|
|
|
+ transactionScope.Complete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (System.Exception ex)
|
|
|
+ {
|
|
|
+ throw new Common.Exceptions.BusinessException(ex.Message);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
}
|
|
|
}
|