Esempio n. 1
0
 public async Task UpdateArticleAsync(ArticleDto article)
 {
     using (var context = new PressfordContext())
     {
         var articleToUpdate = await context.Articles.SingleAsync(art => art.ArticleId == article.ArticleId);
         articleToUpdate.Title = article.Title;
         articleToUpdate.Body = article.Body;
         await context.SaveChangesAsync();
     }
 }
Esempio n. 2
0
 public async Task AddArticleAsync(ArticleDto article)
 {
     using (var context = new PressfordContext())
     {
         context.Users.Attach(article.Author);
         context.Articles.Add(new Article
         {
             Author = article.Author,
             Title = article.Title,
             Body = article.Body,
             PublishDate = DateTime.Now
         }
             );
         await context.SaveChangesAsync();
     }
 }