public async Task UpdateArticleAsync(ArticleInfoModel article, ArticleContentModel articleContentModel) { if (article == null || articleContentModel == null) { throw new ArgumentNullException(); } var ae = ModelEntityHelper.ArticleM2E(article); _dBContext.Articles.Update(ae); await _dBContext.SaveChangesAsync(); }
public async Task AddArticleAsync(ArticleInfoModel article, ArticleContentModel articleContentModel) { if (article == null || articleContentModel == null) { throw new ArgumentNullException(); } using (var trans = _dBContext.Database.BeginTransaction()) { try { string category = article.Category; var categoryEntity = await _dBContext.Categories.Where(c => c.CategoryName == category).SingleOrDefaultAsync(); if (categoryEntity == null) { categoryEntity = new CategoryEntity { CategoryName = category }; } var entity = ModelEntityHelper.ArticleM2E(article); var content = ModelEntityHelper.ContentM2E(articleContentModel); entity.ArticleContent = content; entity.Category = categoryEntity; await _dBContext.Articles.AddAsync(entity); await _dBContext.SaveChangesAsync(); trans.Commit(); } catch { trans.Rollback(); } } }