コード例 #1
0
        public SynonymDtoViewModel Post([FromBody] SynonymDtoViewModel value)

        {
            IList <SynonymDtoViewModel> list      = controller.GetSynonymDtoes();
            SynonymDtoViewModel         viewModel = new SynonymDtoViewModel();
            var synonyms = db.SynonymDtoes.ToList();
            var result   = list.FirstOrDefault(x => x.Term == value.Term);

            viewModel.Term     = result.Term;
            viewModel.Synonyms = result.Synonyms;
            return(viewModel);
        }
コード例 #2
0
        public IList <SynonymDtoViewModel> GetSynonymDtoes()
        {
            var synonymDto = db.SynonymDtoes.ToList();
            List <SynonymDtoViewModel> viewModelList = new List <SynonymDtoViewModel>();

            foreach (SynonymDto synonym in synonymDto)
            {
                SynonymDtoViewModel viewModel = new SynonymDtoViewModel();
                if (viewModelList.Exists(x => x.Term == synonym.Term) == false)
                {
                    viewModel.Term = synonym.Term;
                    IList <string> synonyms = synonym.Synonyms.Split(',');
                    viewModel.Synonyms = synonyms.ToList();
                    viewModelList.Add(viewModel);
                }
            }
            foreach (SynonymDto synonym in synonymDto)
            {
                IList <string> synonyms = synonym.Synonyms.Split(',');
                foreach (string syn in synonyms)
                {
                    var temp = viewModelList.FirstOrDefault(x => x.Term == syn);
                    if (temp != null)
                    {
                        temp.Synonyms.Add(synonym.Term);
                    }
                    else
                    {
                        try
                        {
                            SynonymDtoViewModel viewModel = new SynonymDtoViewModel();
                            viewModel.Term = syn;
                            List <string> lista = new List <string>();
                            lista.Add(synonym.Term);
                            viewModel.Synonyms = lista;
                            viewModelList.Add(viewModel);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                    var temp2 = viewModelList.FirstOrDefault(x => x.Term == synonym.Term);
                    if (temp2.Synonyms.Exists(x => x == syn) == false)
                    {
                        temp2.Synonyms.Add(syn);
                    }
                }
            }
            return(viewModelList);
        }