public void addAnswerToMessage(int messageId, Answer answer)
 {
     foreach (Message message in messageList) {
         if (message.messageId == messageId) {
             message.addAnswer(answer);
             break;
         }
     }
     lastModifiedDate = DateTime.Now.ToString();
 }
Exemplo n.º 2
0
 public void addAnswer(Answer answer)
 {
     answers.Add(answer);
 }
        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 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;
        }