public static TopicMasterVM GetNotes(int TopicID)
        {
            TopicMasterVM tpm = new TopicMasterVM();

            tpm.newComment = new TopicNoteCommentVM();
            using (QuizContext cntxt = new QuizContext())
            {
                var topic = cntxt.TopicMasters.Find(TopicID);

                if (topic != null)
                {
                    tpm.TopicName        = topic.TopicName;
                    tpm.TopicDescription = topic.TopicDescription;
                    tpm.TopicMasterId    = topic.TopicMasterId;
                }

                tpm.TopicNoteVMs = new List <TopicNoteVM>();

                var q = cntxt.TopicNotes.Where(u => u.TopicMasterId == TopicID).ToList();
                if (q != null)
                {
                    if (q.Count > 0)
                    {
                        foreach (var element in q)
                        {
                            TopicNoteVM tpnotes = new TopicNoteVM();
                            tpnotes.TopicNoteId = element.TopicNoteId;
                            tpnotes.NoteTittle  = element.NoteTittle;
                            tpnotes.NoteDesc    = element.NoteDesc;
                            tpnotes.AddedBy     = element.AddedBy;
                            tpnotes.AddedDate   = element.AddedDate;

                            var comments = cntxt.TopicNoteComments.Where(u => u.TopicNoteId == tpnotes.TopicNoteId).ToList();
                            tpnotes.TopicNoteCommentVMs = new List <TopicNoteCommentVM>();
                            if (comments != null)
                            {
                                if (comments.Count > 0)
                                {
                                    foreach (var comment in comments)
                                    {
                                        TopicNoteCommentVM tpnotescomment = new TopicNoteCommentVM();
                                        tpnotescomment.TopicNoteCommentId   = comment.TopicNoteCommentId;
                                        tpnotescomment.TopicNoteCommentDesc = comment.TopicNoteCommentDesc;
                                        tpnotescomment.AddedDate            = comment.AddedDate;
                                        tpnotescomment.AddedBy = comment.AddedBy;
                                        tpnotes.TopicNoteCommentVMs.Add(tpnotescomment);
                                    }
                                }
                            }


                            tpm.TopicNoteVMs.Add(tpnotes);
                        }
                    }
                }
            }

            return(tpm);
        }
        public static List <TopicNoteCommentVM> AddComment(TopicNoteCommentVM topicNoteCommentVM)
        {
            List <TopicNoteCommentVM> mycomments = new List <TopicNoteCommentVM>();

            using (QuizContext cntxt = new QuizContext())
            {
                TopicNoteComment tpcomment = new TopicNoteComment();
                tpcomment.TopicNoteId          = topicNoteCommentVM.TopicNoteCommentId;
                tpcomment.TopicNoteCommentDesc = topicNoteCommentVM.TopicNoteCommentDesc;
                tpcomment.AddedDate            = DateTime.Now;
                tpcomment.AddedBy = topicNoteCommentVM.AddedBy;

                cntxt.TopicNoteComments.Add(tpcomment);
                cntxt.SaveChanges();



                var comments = cntxt.TopicNoteComments.Where(u => u.TopicNoteId == topicNoteCommentVM.TopicNoteId).ToList();
                if (comments != null)
                {
                    if (comments.Count > 0)
                    {
                        foreach (var comment in comments)
                        {
                            TopicNoteCommentVM tpnotescomment = new TopicNoteCommentVM();
                            tpnotescomment.TopicNoteCommentId   = comment.TopicNoteCommentId;
                            tpnotescomment.TopicNoteCommentDesc = comment.TopicNoteCommentDesc;
                            tpnotescomment.AddedDate            = comment.AddedDate;
                            tpnotescomment.AddedBy = comment.AddedBy;
                            mycomments.Add(tpnotescomment);
                        }
                    }
                }
            }

            return(mycomments);
        }
 public List <TopicNoteCommentVM> Post(TopicNoteCommentVM topicNoteCommentVM)
 {
     return(TopicNotesRepo.AddComment(topicNoteCommentVM));
 }