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 DeleteArticleAsync(int articleId) { using (var context = new PressfordContext()) { var article = context.Articles.Attach(new Article { ArticleId = articleId }); context.Articles.Remove(article); await context.SaveChangesAsync(); } }
public async Task LikeArticleAsync(int articleId, int userId) { using (var context = new PressfordContext()) { context.Likes.Add(new Like { ArticleId = articleId, UserId = userId }); await context.SaveChangesAsync(); } }
public async Task LikeArticleAsync(int articleId, int userId) { using (var context = new PressfordContext()) { context.Likes.Add(new Like { ArticleId = articleId, UserId = userId }); await context.SaveChangesAsync(); } }
public async Task AddCommentToArticleAsync(int articleId, int userId, string comment) { using (var context = new PressfordContext()) { var article = context.Articles.Attach(new Article { ArticleId = articleId }); var user = context.Users.Attach(new User { UserId = userId }); context.Comments.Add(new Comment { Article = article, Author = user, PublishDate = DateTime.Now, Content = comment }); 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(); } }
public async Task AddCommentToArticleAsync(int articleId, int userId, string comment) { using (var context = new PressfordContext()) { var article = context.Articles.Attach(new Article { ArticleId = articleId }); var user = context.Users.Attach(new User { UserId = userId }); context.Comments.Add(new Comment { Article = article, Author = user, PublishDate = DateTime.Now, Content = comment }); await context.SaveChangesAsync(); } }
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(); } }
public async Task DeleteArticleAsync(int articleId) { using (var context = new PressfordContext()) { var article = context.Articles.Attach(new Article { ArticleId = articleId }); context.Articles.Remove(article); await context.SaveChangesAsync(); } }