private static void ClearDisciplines(AcademyEntities academyEntities)
 {
     IEnumerable<Discipline> disciplines = academyEntities.Disciplines.ToList();
     foreach (var discipline in disciplines)
     {
         academyEntities.Disciplines.Remove(discipline);
     }
     academyEntities.SaveChanges();
 }
 private static IEnumerable<int> GetDisciplines(IEnumerable<string> names)
 {
     var disciplineNames = new HashSet<string>(names);
     using (var entities = new AcademyEntities())
     {
         return entities.Disciplines.Where(
             x => disciplineNames.Contains(x.Name)).Select(x => x.Id).ToList();
     }
 }
 private static void CreateDiscipline(
     AcademyEntities entities,
     string name,
     Discipline parent)
 {
     var discipline = CreateDiscipline(name, parent);
     entities.Disciplines.Add(discipline);
     entities.SaveChanges();
     foreach (var child in Directory.GetDirectories(name))
     {
         CreateDiscipline(entities, child, discipline);
     }
 }
Beispiel #4
0
 private static void CreateDatabase()
 {
     using (AcademyEntities academyEntities = new AcademyEntities())
     {
         Console.WriteLine("Creating database");
         if (academyEntities.Database.Exists())
         {
             academyEntities.Database.Delete();
         }
         academyEntities.Database.Create();
         //academyEntities.Database.ExecuteSqlCommand("ALTER DATABASE Academy COLLATE Cyrillic_General_CI_AS");
         Console.WriteLine("Database created");
         //Console.WriteLine("Generating test data...");
         //TestDataGenerator generator = new TestDataGenerator(academyEntities);
         //generator.GenerateDisciplines();
         //Console.WriteLine("Generating test data compleeted");
     }
 }
Beispiel #5
0
 public EfDataContext()
 {
     academyEntities = new AcademyEntities();
 }
 public TestDataGenerator(AcademyEntities academyEntities)
 {
     this.academyEntities = academyEntities;
 }
Beispiel #7
0
 public EfDataContext()
 {
     academyEntities = new AcademyEntities();
 }
 private void AddComments(IEntity article, string articleInfo)
 {
     var comments = Regex.Matches(articleInfo, "(?<=text:).*");
     var authors = Regex.Matches(articleInfo, "(?<=author:).*");
     for (int i = 0; i < comments.Count; i++)
     {
         var comment = new Comment();
         comment.ArticleId = article.Id;
         comment.Text = comments[i].Value;
         using (var academyEntities = new AcademyEntities())
         {
             var email = authors[i].Value.TrimEnd('\r');
             comment.UserId = academyEntities.Users.Single(
                 x => x.Email.Equals(email)).Id;
         }
         using (var context = new EfDataContext())
         {
             var publicationService = new PublicationService(context);
             publicationService.Comment(comment);
             var notificationService = new NotificationService(context);
             notificationService.NotifyAboutNewComment(comment);
         }
     }
 }
 private void GenerateDisciplines()
 {
     using (var entities = new AcademyEntities())
     {
         var disciplinesFolder = Path.Combine(testDataFolder, "disciplines");
         var directories = Directory.GetDirectories(disciplinesFolder);
         foreach (var directory in directories)
         {
             CreateDiscipline(entities, directory, null);
         }
     }
 }