public override void Create(Post entity) { #region CreateLabels _labelService.AddRange(entity.Labels); #endregion #region GetLabels + GetCategories + Create entity using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { List <Label> labels = new List <Label>(); foreach (var item in entity.Labels) { labels.Add(_labelRepository.Get(_ => _.Name == item.Name)); } entity.Labels = labels; List <Category> categories = new List <Category>(); foreach (var item in entity.Categories) { categories.Add(_categoryRepository.Get(_ => _.Id == item.Id)); } entity.Categories = categories; base.Create(entity); scope.Complete(); } #endregion }