public void UpdateDetails(IBaseDB baseDB, articleContent content, ICollection <articleComment> comments) { var articleContent = baseDB.Table <articleContent>().FirstOrDefault(x => x.id == content.id); if (articleContent == null) { baseDB.Set <articleContent>().Add(content); } else { baseDB.Entry <articleContent>(content).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } foreach (var item in comments) { var articleComment = baseDB.Table <articleComment>().FirstOrDefault(x => x.id == item.id); if (articleComment == null) { baseDB.Set <articleComment>().Add(articleComment); } else { baseDB.Entry <articleComment>(item).State = Microsoft.EntityFrameworkCore.EntityState.Modified; } } }
public articleInfoDto GetById(Guid id) { var dbEntity = _baseDB.Table <articleInfo>() .FirstOrDefault(x => x.id == id && x.is_del == false); if (dbEntity != null) { LoadDetails(_baseDB, dbEntity); } return(dbEntity != null?_mapper.Map <articleInfoDto>(dbEntity) : null); }
public void LoadDetails(IBaseDB baseDB, articleInfo articleinfo) { articleinfo.article_content = baseDB.Table <articleContent>().FirstOrDefault(x => x.article_info_id == articleinfo.id); articleinfo.article_comments = baseDB.Table <articleComment>().Where(x => x.article_info_id == articleinfo.id).ToList(); }