本文整理汇总了C#中GenericRepository.UpdateAll方法的典型用法代码示例。如果您正苦于以下问题:C# GenericRepository.UpdateAll方法的具体用法?C# GenericRepository.UpdateAll怎么用?C# GenericRepository.UpdateAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GenericRepository
的用法示例。
在下文中一共展示了GenericRepository.UpdateAll方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertOrUpdateArticleAndTraces
private async Task InsertOrUpdateArticleAndTraces(ArticleModel article, IDataService dataService)
{
try
{
using (var unitOfWork = new UnitOfWork(false))
{
article.PrepareForSave();
var addimages = new List<ImageModel>();
var updateimages = new List<ImageModel>();
//article
var addgalleries = new List<GalleryModel>();
var updategalleries = new List<GalleryModel>();
var addgalleryImages = new List<ImageModel>();
var updategalleryImages = new List<ImageModel>();
var addcontents = new List<ContentModel>();
var updatecontents = new List<ContentModel>();
var articleRepo = new GenericRepository<ArticleModel, ArticleEntity>(dataService);
var imageRepo = new GenericRepository<ImageModel, ImageEntity>(dataService);
var galleryRepo = new GenericRepository<GalleryModel, GalleryEntity>(dataService);
var contentRepo = new GenericRepository<ContentModel, ContentEntity>(dataService);
if (article.LeadImage != null)
{
if (article.LeadImage.Id == 0)
addimages.Add(article.LeadImage);
else
updateimages.Add(article.LeadImage);
}
if (article.Content != null && article.Content.Any())
{
foreach (var contentModel in article.Content)
{
if (contentModel.Id == 0)
addcontents.Add(contentModel);
else
updatecontents.Add(contentModel);
if (contentModel.ContentType == ContentType.Gallery && contentModel.Gallery != null)
{
if (contentModel.Gallery.Id == 0)
addgalleries.Add(contentModel.Gallery);
else
updategalleries.Add(contentModel.Gallery);
if (contentModel.Gallery.Images != null)
{
foreach (var imageModel in contentModel.Gallery.Images)
{
if (imageModel.Id == 0)
addgalleryImages.Add(imageModel);
else
updategalleryImages.Add(imageModel);
}
addgalleryImages.AddRange(contentModel.Gallery.Images);
}
}
else if (contentModel.ContentType == ContentType.Image && contentModel.Image != null)
{
if (contentModel.Image.Id == 0)
addimages.Add(contentModel.Image);
else
updateimages.Add(article.LeadImage);
}
}
}
if (article.Themes != null)
await _themeRepository.SetThemesByArticle(article.Id, article.Themes.Select(t => t.Id).ToList());
if (article.RelatedArticles != null)
await SetRelatedArticlesByArticleId(article.Id, article.RelatedArticles.Select(t => t.Id).ToList(), dataService);
await imageRepo.AddAll(addimages);
await galleryRepo.AddAll(addgalleries);
await imageRepo.AddAll(addgalleryImages);
await contentRepo.AddAll(addcontents);
if (article.Id == 0)
await articleRepo.Add(article);
else
await articleRepo.Update(article);
await imageRepo.UpdateAll(updateimages);
await galleryRepo.UpdateAll(updategalleries);
await imageRepo.UpdateAll(updategalleryImages);
await contentRepo.UpdateAll(updatecontents);
await _themeRepository.SaveChanges();
await unitOfWork.Commit();
}
}
catch (Exception ex)
{
LogHelper.Instance.Log(LogLevel.Error, this, "Article cannot be saved", ex);
}
//.........这里部分代码省略.........