private void UpdateResearcherExpertises(string[] selectedOptions, Researcher researcherToUpdate)
        {
            if (selectedOptions == null)
            {
                researcherToUpdate.ResearchExpertises = new List <ResearchExpertise>();
                return;
            }

            var selectedOptionsHS = new HashSet <string>(selectedOptions);
            var resExpertises     = new HashSet <int>(researcherToUpdate.ResearchExpertises.Select(b => b.ExpertiseID));

            foreach (var s in _context.Expertises)
            {
                if (selectedOptionsHS.Contains(s.ID.ToString()))
                {
                    if (!resExpertises.Contains(s.ID))
                    {
                        researcherToUpdate.ResearchExpertises.Add(new ResearchExpertise
                        {
                            ExpertiseID  = s.ID,
                            ResearcherID = researcherToUpdate.ID
                        });
                    }
                }
                else
                {
                    if (resExpertises.Contains(s.ID))
                    {
                        ResearchExpertise specToRemove = researcherToUpdate.ResearchExpertises.SingleOrDefault(d => d.ExpertiseID == s.ID);
                        _context.Remove(specToRemove);
                    }
                }
            }
        }
示例#2
0
        private void UpdatePaperKeywords(string[] selectedOptions, PaperInfo paperInfoToUpdate)
        {
            if (selectedOptions == null)
            {
                paperInfoToUpdate.PaperKeywords = new List <PaperKeyword>();
                return;
            }

            var selectedOptionsHS = new HashSet <string>(selectedOptions);
            var papKey            = new HashSet <int>(paperInfoToUpdate.PaperKeywords.Select(b => b.KeywordID));

            foreach (var s in _context.Keywords)
            {
                if (selectedOptionsHS.Contains(s.ID.ToString()))
                {
                    if (!papKey.Contains(s.ID))
                    {
                        paperInfoToUpdate.PaperKeywords.Add(new PaperKeyword
                        {
                            KeywordID   = s.ID,
                            PaperInfoID = paperInfoToUpdate.ID
                        });
                    }
                }
                else
                {
                    if (papKey.Contains(s.ID))
                    {
                        PaperKeyword specToRemove = paperInfoToUpdate.PaperKeywords.SingleOrDefault(d => d.KeywordID == s.ID);
                        _context.Remove(specToRemove);
                    }
                }
            }
        }