|
|
|
@ -7,6 +7,7 @@ using Newtonsoft.Json.Linq; |
|
|
|
|
using SqlSugar; |
|
|
|
|
using Tiobon.Core.Common; |
|
|
|
|
using Tiobon.Core.Common.Caches; |
|
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
|
using Tiobon.Core.IRepository.Base; |
|
|
|
|
using Tiobon.Core.IServices; |
|
|
|
|
using Tiobon.Core.Model; |
|
|
|
@ -48,7 +49,11 @@ public class Ghre_CourseWareServices : BaseServices<Ghre_CourseWare, Ghre_Course |
|
|
|
|
entity.CourseNames = string.Join(",", courses.Select(x => x.CourseName)); |
|
|
|
|
} |
|
|
|
|
var result = await base.Add(entity); |
|
|
|
|
entity.Attachments.ForEach(x => x.CourseWareId = result); |
|
|
|
|
entity.Attachments.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.CourseWareId = result; |
|
|
|
|
x.RelativePath = x.RelativePath.Replace("/Advanced", null); |
|
|
|
|
}); |
|
|
|
|
await _ghre_CourseWareAttachmentServices.Add(entity.Attachments); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
@ -63,7 +68,11 @@ public class Ghre_CourseWareServices : BaseServices<Ghre_CourseWare, Ghre_Course |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await _ghre_CourseWareAttachmentServices.Delete(x => x.CourseWareId == Id); |
|
|
|
|
editModel.Attachments.ForEach(x => x.CourseWareId = Id); |
|
|
|
|
editModel.Attachments.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
x.CourseWareId = Id; |
|
|
|
|
x.RelativePath = x.RelativePath.Replace("/Advanced", null); |
|
|
|
|
}); |
|
|
|
|
await _ghre_CourseWareAttachmentServices.Add(editModel.Attachments); |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -86,6 +95,10 @@ public class Ghre_CourseWareServices : BaseServices<Ghre_CourseWare, Ghre_Course |
|
|
|
|
else result.result.DT_TableDataT1[0].CourseIds2 = new List<long>(); |
|
|
|
|
|
|
|
|
|
result.result.DT_TableDataT1[0].Attachments = await _ghre_CourseWareAttachmentServices.Query(x => x.CourseWareId == body.id); |
|
|
|
|
if (result.result.DT_TableDataT1[0].Attachments.Any()) |
|
|
|
|
{ |
|
|
|
|
result.result.DT_TableDataT1[0].Attachments.ForEach(x => x.RelativePath = "/Advanced" + x.RelativePath); |
|
|
|
|
} |
|
|
|
|
var IDS = result.result.DT_TableDataT1[0].CourseIds2; |
|
|
|
|
result.result.DT_TableDataT1[0].Courses = await _ghre_CourseServices.Query(x => IDS.Contains(x.Id)); |
|
|
|
|
|
|
|
|
@ -202,13 +215,23 @@ public class Ghre_CourseWareServices : BaseServices<Ghre_CourseWare, Ghre_Course |
|
|
|
|
var attachments = await _ghre_CourseWareAttachmentServices.Query(x => x.CourseWareId == id); |
|
|
|
|
var webRootPath = _hostingEnvironment.WebRootPath; |
|
|
|
|
var outPath = $"/files/upload/{result.CourseWareName}_{result.VersionNo}_{DateTime.Now.ToString("yyyyMMddHHmmss")}.zip"; |
|
|
|
|
var files = attachments.Select(x => $"{webRootPath}{"\\" + x.RelativePath}").ToArray(); |
|
|
|
|
if (files.Length > 0) |
|
|
|
|
if (attachments.Any()) |
|
|
|
|
{ |
|
|
|
|
var newFilePath = $"{webRootPath}/files/upload/{SnowFlakeSingle.Instance.NextId()}"; |
|
|
|
|
|
|
|
|
|
Directory.CreateDirectory(newFilePath); |
|
|
|
|
|
|
|
|
|
attachments.ForEach(x => |
|
|
|
|
{ |
|
|
|
|
if (File.Exists($"{webRootPath}{"\\" + x.RelativePath}")) |
|
|
|
|
FileHelper.FileCoppy($"{webRootPath}{"\\" + x.RelativePath}", $"{newFilePath}/{x.AttachmentName}"); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
var files = attachments.Select(x => $"{newFilePath}{"\\" + x.AttachmentName}").ToArray(); |
|
|
|
|
if (files.Length > 1) |
|
|
|
|
CreateZip($"{webRootPath}{outPath}", files); |
|
|
|
|
else |
|
|
|
|
outPath = attachments[0].RelativePath; |
|
|
|
|
outPath = newFilePath + "/" + attachments[0].AttachmentName; |
|
|
|
|
return ServiceResult<string>.OprateSuccess(null, "/Advanced" + outPath); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|