public async Task <Article> UpdateArticleAsync(string articleId, UpdateArticleRequest updateArticleIn) { var filter = Builders <DataAccessArticle> .Filter.Eq(s => s.Id, articleId); var update = Builders <DataAccessArticle> .Update.Set(s => s.Title, updateArticleIn.Title).Set(s => s.Content, updateArticleIn.Content); DataAccessArticle dbArticle = await _dbContext.Articles.FindOneAndUpdateAsync(filter, update); return(_mapper.Map <Article>(dbArticle)); }
public async Task <Article> AddArticleAsync(UpdateArticleRequest updateArticleIn) { var dbArticles = await _dbContext.Articles.FindAsync(article => article.Title == updateArticleIn.Title); if (dbArticles.Any()) { throw new RequestedResourceHasConflictException(); } var dbUser = await _dbContext.Users.Find(x => x.Id == updateArticleIn.UserId).FirstOrDefaultAsync(); if (dbUser == null) { throw new RequestedResourceNotFoundException(); } DataAccessArticle dbArticle = _mapper.Map <UpdateArticleRequest, DataAccessArticle>(updateArticleIn); dbArticle.User = dbUser; await _dbContext.Articles.InsertOneAsync(dbArticle); return(_mapper.Map <Article>(dbArticle)); }