public override async Task <Article> FavoriteArticle(string authedUsername, string slug) { var transaction = _context.Database.BeginTransaction(); try { IdentityUser user = await _userManager.FindByNameAsync(authedUsername); ArticleDAO articleDao = await _articleRepository.GetArticleBySlug(slug); FavoriteArticleDAO favoriteArticle = new FavoriteArticleDAO { ArticleId = articleDao.Id, UserId = user.Id }; _favoriteArticleRepository.FavoriteArticle(favoriteArticle); _context.SaveChanges(); articleDao = await _articleRepository.GetArticleBySlug(slug); transaction.Commit(); Article article = await CreateArticleFromDAO(articleDao, authedUsername); return(article); } catch (Exception ex) { transaction.Rollback(); throw ex; } }
internal override void UnfavoriteArticle(int id, string userId) { FavoriteArticleDAO favoriteArticle = _favoriteArticle.Where(e => e.UserId == userId && e.ArticleId == id).Single(); _favoriteArticle.Remove(favoriteArticle); }
internal override void FavoriteArticle(FavoriteArticleDAO favoriteArticle) { _favoriteArticle.Add(favoriteArticle); }
internal abstract void FavoriteArticle(FavoriteArticleDAO favoriteArticle);