Esempio n. 1
0
 private static void TestChildDisciplines()
 {
     using (IDataContext context = new EfDataContext())
     {
         var storage = context.DisciplineStorage;
         var disciplines = SelectDisciplines(storage);
         var allChildren = storage.Get(disciplines.Select(x => x.Id));
         foreach (var discipline in allChildren)
         {
             Console.WriteLine(discipline.Name);
         }
     }
 }
Esempio n. 2
0
 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);
         }
     }
 }
Esempio n. 3
0
 private void CreateArticle(string articleFile, StreamWriter writer)
 {
     string articleInfo = File.ReadAllText(articleFile, Encoding.GetEncoding(1251));
     var article = new Article();
     article.Title = GetInfoField(articleInfo, "title");
     writer.WriteLine("Title: {0}", article.Title);
     article.Text = GetInfoField(articleInfo, "description");
     article.Source = GetInfoField(articleInfo, "source");
     var authors = GetInfoField(articleInfo, "users").Split(',');
     article.Authors = new List<User>();
     foreach (var author in authors)
     {
         article.Authors.Add(new User { Email = author.TrimEnd('\r') });
     }
     var disciplineIds = GetDisciplines(GetInfoField(articleInfo, "disciplines").Split(','));
     article.Disciplines = new List<Discipline>();
     foreach (var disciplineId in disciplineIds)
     {
         article.Disciplines.Add(new Discipline() { Id = disciplineId });
     }
     using (var dataContext = new EfDataContext())
     {
         var publicationService = new PublicationService(dataContext);
         publicationService.Publish(article);
         var notificationService = new NotificationService(dataContext);
         notificationService.NotifyAboutNewArticle(article);
     }
     AddComments(article, articleInfo);
 }