Ejemplo n.º 1
0
        /// <summary>
        /// 根据课文ID取查询课文的单词 适用于作业模式
        /// </summary>
        /// <param name="workId"></param>
        /// <returns></returns>
        public WorkConents <List <WordContract> > GetWordsByWorkId(long contentId, long publishId)
        {
            var workPackage  = workService.GetWorkPackage(publishId);  //获取作业布置信息
            var workResource = workService.GetWorkResource(contentId); //获取作业资源包信息

            if (null == workPackage || null == workResource)
            {
                throw new Exception("未找到指定的作业资源");
            }

            var words = new List <WordContract>();                                                        //定义作业单词数据列表容器

            if (workResource.IsFull)                                                                      //如果子资源就取子资源内容
            {
                var wordIds = workService.GetResourceParts(contentId).Select(t => t.VersionId).ToArray(); //查询子资源中单词ID列表
                words = this.GetByVersionIds <WordContract>(wordIds).Data.ToList();
            }
            else //没有布置子资源取全文单词列表
            {
                words = GetWordsByVersionId(workResource.VersionId).ResList;//查询单词列表
            }

            //处理音频文件为空的情况
            words.ForEach(t =>
            {
                if (t.AudioUrl == null || t.AudioUrl == "False")
                {
                    t.AudioUrl = "";
                }
                t.Sentences.ToList().ForEach(item =>
                {
                    if (item.AudioUrl == null || item.AudioUrl == "False")
                    {
                        item.AudioUrl = "";
                    }
                });
            });

            //返回作业单词内容
            return(new CiWong.Resource.Preview.DataContracts.WorkConents <List <CiWong.Tools.Workshop.DataContracts.WordContract> >()
            {
                Content = words,
                WorkInfo = workResource,
                WorkPublishInfo = workPackage
            });
        }