public DictionariesControl(Window owner)
        {
            InitializeComponent();
            DataContext = new DictionariesViewModel();
            foreach (var tab in ((DictionariesViewModel)DataContext).DictionariesTabs)
            {
                tab.MessageBoxDisplayRequested += (sender, args) =>
                {
                    CustomMessageBox.Show(args.Title, args.Text);
                };

                tab.DialogDisplayRequested += (sender, args) =>
                {
                    if (!(args.Record is SimpleRecord record))
                    {
                        return;
                    }
                    var view = new DictionaryRecordDialog(tab.Dictionary, record)
                    {
                        Owner = owner
                    };
                    view.ShowDialog();
                };
            }
        }
Example #2
0
        public ActionResult Index(string option)
        {
            if (option != null)
            {
                switch (option.ToLower())
                {
                case "dictionaries":
                {
                    _viewModel = new DictionariesViewModel();
                    CreateLayoutView("Từ điển");
                    break;
                }

                case "oldwords":
                {
                    _viewModel = new OldWordsViewModel();
                    CreateLayoutView("Danh sách từ yêu thích");
                    break;
                }

                default:
                {
                    _viewModel = new DictionariesViewModel();
                    CreateLayoutView("Từ điển");
                    break;
                }
                }
            }
            else
            {
                _viewModel = new DictionariesViewModel();
                CreateLayoutView("Từ điển");
            }

            return(View(_viewModel));
        }
Example #3
0
        public async Task <PartialViewResult> Dictionaries(string keyword)
        {
            bool        isVN            = false;
            OxfordDict  dict            = new OxfordDict();
            GoogleTrans googleTransJson = new GoogleTrans();

            keyword    = keyword.Trim();
            _viewModel = new DictionariesViewModel();
            bool downloadSucceeded = false;

            if (keyword != "")
            {
                int size = keyword.Split(' ').Length;
                if (size > 1)
                {
                    googleTransJson = await _clientDictionaryService.startGoogleTrans(keyword);

                    DictionariesViewModel.isGoogleTrans = true;
                    DictionariesViewModel.m_GoogleTrans = googleTransJson;
                }
                else
                {
                    try
                    {
                        dict = await _clientDictionaryService.startCrawlerOxford(keyword);

                        downloadSucceeded = true;
                    }
                    catch (Exception e)
                    {
                        downloadSucceeded = false;
                    }
                    if (!downloadSucceeded)
                    {
                        googleTransJson = await _clientDictionaryService.startGoogleTrans(keyword);

                        if (googleTransJson.src == "vi")
                        {
                            isVN = true;
                        }
                        DictionariesViewModel.isGoogleTrans = true;
                        DictionariesViewModel.m_GoogleTrans = googleTransJson;
                    }
                    try
                    {
                        GoogleTrans detailVietnamese = new GoogleTrans();
                        detailVietnamese = await _clientDictionaryService.startGoogleDetailTrans(keyword);

                        if (detailVietnamese.src == "vi")
                        {
                            isVN = true;
                        }
                        string meanVN = detailVietnamese.dict.First().pos + ": ";
                        foreach (var item in detailVietnamese.dict.First().terms)
                        {
                            meanVN += item + ", ";
                        }
                        DictionariesViewModel.m_MeanVn = meanVN;
                    }
                    catch
                    {
                    }
                    DictionariesViewModel.m_Explanation = dict.m_Explanation;
                    DictionariesViewModel.m_SoundUrl    = dict.m_SoundUrl;
                    DictionariesViewModel.m_Type        = dict.m_Type;
                    DictionariesViewModel.m_Voca        = dict.m_Voca;
                    DictionariesViewModel.m_Pron        = dict.m_Pron.Replace("BrE", "");
                }
                DictionariesViewModel.m_ExaTraCau = await _clientDictionaryService.startCrawlerTraCau(keyword);
            }
            try
            {
                DictCache dictCache = _dictCache.findWordCache(keyword);
                if (dictCache == null)
                {
                    dictCache          = new DictCache();
                    dictCache.VocaID   = keyword;
                    dictCache.Pron     = DictionariesViewModel.m_Pron;
                    dictCache.MeanEn   = DictionariesViewModel.m_Explanation.FirstOrDefault().m_UseCase;
                    dictCache.MeanVi   = DictionariesViewModel.m_MeanVn;
                    dictCache.SoundUrl = DictionariesViewModel.m_SoundUrl;
                    _dictCache.Add(dictCache);
                    _dictCache.Save();
                }
                else
                {
                    if (_detailOutWordService.findDetailOurWord(User.Identity.GetUserId(), dictCache.Id) != null)
                    {
                        DictionariesViewModel.love = true;
                    }
                }
            }
            catch (Exception e)
            {
            }
            return(PartialView("_Dictionaries", DictionariesViewModel));
        }