private void LoadLangs() { this.Langs.Clear(); DbSet<PrfLang> langs = this.DataService.GetDbSet<PrfLang>(); List<String> codeIsos = (from l in langs select l.CodeIso).Distinct().ToList(); String defaultCodeIso = "fra"; DbSet<PrfParam> parameters = this.DataService.GetDbSet<PrfParam>(); PrfParam paramDefaultLang = (from p in parameters where p.Code.Equals("LANG") select p).FirstOrDefault(); if (paramDefaultLang == null) { PrfParam param = new PrfParam(); param.Code = "LANG"; param.Valeur = "fra"; parameters.Add(param); this.DataService.DataContext.SaveChanges(); } else { defaultCodeIso = paramDefaultLang.Valeur; } foreach (String codeIso in codeIsos) { LangViewModel vm = new LangViewModel(); vm.CodeIso = codeIso; vm.DisplayName = codeIso; this.Langs.Add(vm); if (codeIso.Equals(defaultCodeIso)) { this._selectedLang = vm; this.RaisePropertyChanged("SelectedLang"); } } }
private void ChangeCurrentLang() { DbSet<PrfParam> parameters = this.DataService.GetDbSet<PrfParam>(); List<PrfParam> itemToRemoves = (from p in parameters where p.Code.Equals("LANG") select p).ToList (); foreach (PrfParam itemToRemove in itemToRemoves) {parameters.Remove(itemToRemove);} this.DataService.DataContext.SaveChanges(); if (this._selectedLang != null) { PrfParam param = new PrfParam(); param.Code = "LANG"; param.Valeur = this._selectedLang.CodeIso; parameters.Add(param); this.DataService.DataContext.SaveChanges(); ServiceLocator.Current.GetInstance<ITranslateService>().LoadCurrentLang(); } }