private void AddResources(string[] filenames) { foreach (var filename in filenames) { var resource = MediaResource.Create(System.IO.Path.GetFileName(filename), filename, _mediaResourceType); _mediaResources.Add(resource); _mediaResourceRepository.Add(resource); } }
public void AddMediaResource(DtoResourceRequest resource) { using (TransactionScope scope = new TransactionScope()) { try { int textObjectId = 0; if (!string.IsNullOrEmpty(resource.AudioContent)) { textObjectId = AddTextObject(resource.AudioContent, resource.Status, resource.Creator); } var mediaObjectId = AddMediaObject((int)resource.MediaObjectType, resource.Url, resource.ImgId, textObjectId, resource.Description, resource.Creator); Yw_MediaResource mediaResource = new Yw_MediaResource() { Ymr_Name = resource.Name, Ymr_MediaType = (int)resource.MediaType, Ymr_CreateTime = DateTime.Now, Ymr_Grade = resource.Grade, Ymr_Status = resource.Status, Ymr_MediaObjectId = mediaObjectId, Ymr_Keywords = resource.Keyword, Ymr_UpdateTime = DateTime.Now, Ymr_Creator = resource.Creator, Ymr_Editor = resource.Editor }; MediaResourceRepository.Add(mediaResource); if (resource.MediaType != MediaResourceTypeEnum.小艾变 && resource.MediaType != MediaResourceTypeEnum.开场语) { var words = GetWords(resource.Name, resource.Keyword, resource.Grade); AddResourceIndex(resource.Name, resource.Grade, (int)resource.ResourceType, mediaResource.Ymr_Id, (int)ResourceTypeEnum.多媒体资源, words, resource.Creator); } scope.Complete(); } catch (Exception ex) { RollbackTran(); throw ex; } } }