public virtual async Task <DynamicProperty[]> SaveDynamicPropertiesAsync(DynamicProperty[] properties) { if (properties == null) { throw new ArgumentNullException(nameof(properties)); } var pkMap = new PrimaryKeyResolvingMap(); using (var repository = _repositoryFactory()) { var dbExistProperties = (await repository.GetDynamicPropertiesForTypesAsync(properties.Select(x => x.ObjectType).Distinct().ToArray())).ToList(); foreach (var property in properties) { var originalEntity = dbExistProperties.FirstOrDefault(x => property.IsTransient() ? x.Name.EqualsInvariant(property.Name) && x.ObjectType.EqualsInvariant(property.ObjectType) : x.Id.EqualsInvariant(property.Id)); var modifiedEntity = AbstractTypeFactory <DynamicPropertyEntity> .TryCreateInstance().FromModel(property, pkMap); if (originalEntity != null) { modifiedEntity.Patch(originalEntity); } else { repository.Add(modifiedEntity); } } repository.UnitOfWork.Commit(); pkMap.ResolvePrimaryKeys(); DynamicPropertiesCacheRegion.ExpireRegion(); } return(properties); }
public virtual async Task SaveDictionaryItemsAsync(DynamicPropertyDictionaryItem[] items) { if (items == null) { throw new ArgumentNullException(nameof(items)); } using (var repository = _repositoryFactory()) { var dbExistItems = await repository.GetDynamicPropertyDictionaryItemByIdsAsync(items.Where(x => !x.IsTransient()).Select(x => x.Id).ToArray()); foreach (var item in items) { var originalEntity = dbExistItems.FirstOrDefault(x => x.Id == item.Id); var modifiedEntity = AbstractTypeFactory <DynamicPropertyDictionaryItemEntity> .TryCreateInstance().FromModel(item); if (originalEntity != null) { modifiedEntity.Patch(originalEntity); } else { repository.Add(modifiedEntity); } } await repository.UnitOfWork.CommitAsync(); DynamicPropertiesCacheRegion.ExpireRegion(); } }
public virtual async Task DeleteDynamicPropertiesAsync(string[] propertyIds) { if (propertyIds == null) { throw new ArgumentNullException(nameof(propertyIds)); } using (var repository = _repositoryFactory()) { var properties = repository.DynamicProperties.Where(p => propertyIds.Contains(p.Id)) .ToList(); foreach (var property in properties) { repository.Remove(property); } await repository.UnitOfWork.CommitAsync(); DynamicPropertiesCacheRegion.ExpireRegion(); } }
public virtual async Task DeleteDictionaryItemsAsync(string[] itemIds) { if (itemIds == null) { throw new ArgumentNullException(nameof(itemIds)); } using (var repository = _repositoryFactory()) { var items = repository.DynamicPropertyDictionaryItems .Where(v => itemIds.Contains(v.Id)) .ToList(); foreach (var item in items) { repository.Remove(item); } await repository.UnitOfWork.CommitAsync(); DynamicPropertiesCacheRegion.ExpireRegion(); } }