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(); } }
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(); } }