public void AddPaperToTopic(PaperEntity paper, long topicId)
 {
     CreateDAO().Insert(paper);
     base.Insert(new TopicPaper {
         PaperId = paper.PaperId, TopicId = topicId
     });
 }
        public ActionResult BatchAddPapers(string spaceKey, BatchDois batchdois)
        {
            long   topicId    = topicService.GetTopicIdByTopicKey(spaceKey);
            string doisstring = batchdois.dois;

            doisstring = doisstring.ToLower().Replace(" ", "");
            doisstring = doisstring.Replace("doi:", "");
            string[] dois = doisstring.Split(new string[] { "<br/>" }, System.StringSplitOptions.RemoveEmptyEntries);

            string doiQueryStr = "";

            if (dois.Count() < 1)
            {
                return(View(batchdois));
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                foreach (string doi in dois)
                {
                    PaperEntity paper = paperService.GetPaperByPaperDOI(doi);
                    if (paper == null)
                    {
                        sb.Append(doi);
                        sb.Append(" or ");
                    }
                    else
                    {
                        if (!paperService.TopicPaperExist(topicId, paper.PaperId))
                        {
                            paperService.AddPaperToTopic(paper.PaperId, topicId);
                        }
                    }
                }
                doiQueryStr = sb.ToString();
                doiQueryStr = doiQueryStr.Substring(0, doiQueryStr.Length - 4);
            }
            PubMedService     pmService      = new PubMedService();
            List <PubMedItem> pubmedItemList = pmService.GetCitationsFromDOIs(doiQueryStr);

            foreach (PubMedItem pubItem in pubmedItemList)
            {
                //todo:1 add pubitem to paperrepository
                //PaperEntity p = pubItem.AsPaperEntity();
                //paperService.Create(p);
                //todo:2 add pubitem to topicpaperrepository
                //paperService.AddPaperToTopic(
                paperService.AddPaperToTopic(topicId, pubItem.AsPaperEntity());
            }


            return(View(batchdois));
        }
        public PaperDTO ToDTO(PaperEntity ef)
        {
            PaperDTO dto = new PaperDTO();

            dto.Id             = ef.Id;
            dto.ExamTime       = ef.ExamTime;
            dto.CreateDateTime = ef.CreateDateTime;
            dto.PCount         = ef.PCount;
            dto.PScore         = ef.PScore;
            dto.Title          = ef.Title;
            dto.ZScore         = ef.ZScore;
            return(dto);
        }
 public int AddPaper(PaperDTO dto)
 {
     using (MyDbContext ctx = new MyDbContext())
     {
         PaperEntity ef = new PaperEntity();
         ef.Title    = dto.Title;
         ef.PCount   = dto.PCount;
         ef.PScore   = dto.PScore;
         ef.ExamTime = dto.ExamTime;
         ef.ZScore   = dto.ZScore;
         ctx.Papers.Add(ef);
         ctx.SaveChanges();
         return(ef.Id);
     }
 }