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 void RegisterNew <TEntity>(TEntity obj) where TEntity : AggregateRoot { var state = context.Entry(obj).State; if (state == EntityState.Detached) { context.Entry(obj).State = EntityState.Added; } IsCommitted = false; }
public bool Update(articleInfoDto entity) { var dbEntity = _mapper.Map <articleInfo>(entity); _baseDB.Entry <articleInfo>(dbEntity).State = Microsoft.EntityFrameworkCore.EntityState.Modified; UpdateDetails(_baseDB, dbEntity.article_content, dbEntity.article_comments); return(_baseDB.Commit()); }