Exemple #1
0
        private static void CreateNiveauEcrit(LanguagesDbContext context)
        {
            if (context != null && !context.NiveauxEcrits.Any())
            {
                //create levels of comprehension
                var base_level = new NiveauEcrit()
                {
                    Guid = Guid.NewGuid(),
                    Name = "bas",
                    IsDefaultValueInstance = true
                };
                var fluent_level = new NiveauEcrit()
                {
                    Guid = Guid.NewGuid(),
                    Name = "courant"
                };
                var excelent_level = new NiveauEcrit()
                {
                    Guid = Guid.NewGuid(),
                    Name = "excellent"
                };

                //add them to table
                context.NiveauxEcrits.AddRange(new NiveauEcrit[] { base_level, fluent_level, excelent_level });
                context.SaveChanges();
            }
        }
Exemple #2
0
 private static void CreateLanguages(LanguagesDbContext context)
 {
     if (context != null && !context.Languages.Any())
     {
         var directory  = Environment.CurrentDirectory;
         var pathToFile = Path.Combine(directory, @"Helpers\Files\",
                                       LanguageRessources.LanguagesListFileName);
         var languagesToSave = Transformer.GetLanguagesFromFile <Language>(pathToFile);
         if (languagesToSave != null && languagesToSave.Count > 0)
         {
             context.Languages.AddRange(languagesToSave.ToArray());
             context.SaveChanges();
         }
     }
 }
Exemple #3
0
 private static void CreateDefaultUserConfiguredLanguages(LanguagesDbContext context)
 {
     if (context != null && !context.UserConfiguredLanguages.Any())
     {
         //get the compulsory languages and configure default
         var compulsoryLanguages = context.Languages.Where(l => l.IsCompulsoryToTheApplication).ToList();
         if (compulsoryLanguages != null && compulsoryLanguages.Count > 0)
         {
             List <UserConfiguredLanguage> defaultConfiguredLanguages = new List <UserConfiguredLanguage>();
             //get default levels
             var defaultTalkLevel       = context.NiveauxParles.FirstOrDefault(np => np.IsDefaultValueInstance);
             var defaultWriteLevel      = context.NiveauxEcrits.FirstOrDefault(ne => ne.IsDefaultValueInstance);
             var defaultUnderstandLevel = context.NiveauxComprehensions.FirstOrDefault(nc => nc.IsDefaultValueInstance);
             if (defaultTalkLevel != null && defaultWriteLevel != null && defaultUnderstandLevel != null)
             {
                 //configure the user compulsory languages
                 foreach (var compulsoryLanguage in compulsoryLanguages)
                 {
                     if (compulsoryLanguage != null)
                     {
                         defaultConfiguredLanguages.Add(new UserConfiguredLanguage()
                         {
                             Guid                      = Guid.NewGuid(),
                             DateCreated               = DateTime.Now,
                             LastModifiedDate          = DateTime.Now,
                             LanguageGuid              = compulsoryLanguage.Guid,
                             LanguageConcerned         = compulsoryLanguage,
                             NiveauParleGuid           = defaultWriteLevel.Guid,
                             NiveauEcritGuid           = defaultWriteLevel.Guid,
                             NiveauComprehensionGuid   = defaultUnderstandLevel.Guid,
                             NiveauParle               = defaultTalkLevel,
                             NiveauEcrit               = defaultWriteLevel,
                             IsApplicationUserLanguage = compulsoryLanguage.Code.ToLower() == "fr",
                             NiveauComprehension       = defaultUnderstandLevel,
                         });
                     }
                 }
                 context.UserConfiguredLanguages.AddRange(defaultConfiguredLanguages.ToArray());
                 context.SaveChanges();
             }
         }
     }
 }