public List<KnowledgePoint> GetKnowledgePointList(string courseCode, string CourseNumber) { List<KnowledgePoint> list = new List<KnowledgePoint>(); KnowledgePointTableAdapter kpAdapter = new KnowledgePointTableAdapter(); KnowledgePointParentChildRelationTableAdapter kpRelationAdatper = new KnowledgePointParentChildRelationTableAdapter(); KnowledgePointAssetRelationTableAdapter kpAssetAdapter = new KnowledgePointAssetRelationTableAdapter(); CourseTableAdapter courseAdapter = new CourseTableAdapter(); var courseIdList = courseAdapter.GetIdByCourseDetails(courseCode, Convert.ToInt32(CourseNumber)); int courseId = courseIdList[0].Id; PriorityTableAdapter priorityAdapter = new PriorityTableAdapter(); AssetTableAdapter assetAdapter = new AssetTableAdapter(); AssetTypeTableAdapter assetTypeAdapter = new AssetTypeTableAdapter(); foreach (var row in kpAdapter.GetKnowledgePointByCourseId(courseId)) { KnowledgePoint kp = new KnowledgePoint(row.Id, courseCode + CourseNumber, row.Name, row.xPos, row.yPos); kp.priority = (Priority)Enum.Parse(typeof(Priority), priorityAdapter.GetPriorityById(row.Priority)[0].Priority); kp.createDate = row.CreatedTime.ToString("G"); kp.modifiedDate = row.LastModifiedTime.ToString("G"); foreach (var relation in kpRelationAdatper.GetParentIdByChildId(row.Id)) { kp.addParent(relation.ParentKnowledgePointId); } foreach (var relatedAsset in kpAssetAdapter.GetAssetListByKnowledgePointId(row.Id)) { foreach (var assetPointer in assetAdapter.GetAssetDetailById(relatedAsset.AssetId)) { AssetType type = (AssetType)Enum.Parse(typeof(AssetType), assetTypeAdapter.GetDataById(assetPointer.AssetType)[0].AssetType); if (type == AssetType.PDF | type == AssetType.PPT | type == AssetType.Audio | type == AssetType.Video) { AssetPointer pointer = new AssetPointer(assetPointer.Id, assetPointer.Path + assetPointer.AssetName, type, relatedAsset.Start, relatedAsset.End); kp.addAsset(pointer); } else if (type == AssetType.SelfTest) { int selftestId = Convert.ToInt32(assetPointer.AssetName); SelfTestTableAdapter stAdapter = new SelfTestTableAdapter(); var st = stAdapter.GetSelfTestDataById(Convert.ToInt32(assetPointer.AssetName))[0]; SelfTestQuesion stQuestion = new SelfTestQuesion(st.Question, st.AnswerKey); kp.addTestQuestion(stQuestion); } else if (type == AssetType.QandA) { int messageId = Convert.ToInt32(assetPointer.AssetName); QandATableAdapter qaAdapter = new QandATableAdapter(); var qa = qaAdapter.GetQAsById(messageId)[0]; Message message = new Message(qa.Id, "user Id: " + qa.AskedBy, qa.Question); try { string answerTypeString = (new AnswerTypeTableAdapter()).GetDataById(qa.AnswerType)[0].AnswerType; Answer answer = new Answer(answerTypeString, qa.Answer); } catch { } finally { message.addAnswer(new Answer(AnswerType.NoAnswer, "")); } message.createTime = qa.CreatedTime.ToString("G"); kp.messageBox.lastModifiedDate = qa.CreatedTime.ToString("G"); kp.addMessage(message); } } } kp.createDate = row.CreatedTime.ToString("G"); kp.modifiedDate = row.LastModifiedTime.ToString("G"); list.Add(kp); } return list; }
public string insertAnswerToMessage(string courseCode, string courseNumber, string messageId, string answer, string answerTypeId) { QandATableAdapter qaAdapter = new QandATableAdapter(); CourseTableAdapter courseAdapter = new CourseTableAdapter(); var table = courseAdapter.GetIdByCourseDetails(courseCode, Convert.ToInt32(courseNumber)); if (table.Count > 0) { if (qaAdapter.GetQAsById(Convert.ToInt32(messageId)).Count > 0) { qaAdapter.AddAnswerToQuestion(answer, Convert.ToInt32(answerTypeId), DateTime.Now, Convert.ToInt32(messageId)); return "success"; } } return "failed"; }
public string insertNewMessage(string courseCode, string courseNumber, string userId, string message) { QandATableAdapter qaAdapter = new QandATableAdapter(); CourseTableAdapter courseAdapter = new CourseTableAdapter(); AssetTableAdapter assetAdapter = new AssetTableAdapter(); var table = courseAdapter.GetIdByCourseDetails(courseCode, Convert.ToInt32(courseNumber)); if (table.Count > 0) { qaAdapter.InsertNewQuestion(message, Convert.ToInt32(userId), null, null, DateTime.Now, null, Convert.ToInt32(table[0].Id)); var qaTable = qaAdapter.GetMessageListByCourseId(Convert.ToInt32(table[0].Id)); int qaID = qaTable[qaTable.Count-1].Id; assetAdapter.InsertAsset(qaID.ToString(), qaID.ToString(), 3104); return "success"; } return "failed"; }
public MessageBox GetMessageBox(string courseCode, string courseNumber) { MessageBox messageBox = new MessageBox(courseCode + courseNumber, ""); QandATableAdapter qaAdapter = new QandATableAdapter(); CourseTableAdapter courseAdapter = new CourseTableAdapter(); var courseIdList = courseAdapter.GetIdByCourseDetails(courseCode, Convert.ToInt32(courseNumber)); int courseId = courseIdList[0].Id; var qaTable = qaAdapter.GetMessageListByCourseId(courseId); AnswerTypeTableAdapter answerTypeAdapter = new AnswerTypeTableAdapter(); UserDataTableAdapter userAdapter = new UserDataTableAdapter(); foreach (var row in qaTable) { int userId = row.AskedBy; string username = userAdapter.GetUserDataById(userId)[0].Username; Message message = new Message(username, row.Question); message.createTime = row.CreatedTime.ToString("G"); message.messageId = row.Id; try { Answer answer = new Answer(row.AnswerType, row.Answer); message.addAnswer(answer); } catch (StrongTypingException e) { } messageBox.addMessage(message); } return messageBox; }