public async Task <ModelConfigurationDto> CreateAsync(ModelConfigurationDto input) { var modelConfig = new EntityConfig(); // todo: add validation return(await CreateOrUpdateAsync(modelConfig, input)); }
public async Task <ModelConfigurationDto> UpdateAsync(ModelConfigurationDto input) { var modelConfig = await _entityConfigRepository.GetAll().Where(m => m.Id == input.Id).FirstOrDefaultAsync(); if (modelConfig == null) { new EntityNotFoundException("Model configuration not found"); } // todo: add validation return(await CreateOrUpdateAsync(modelConfig, input)); }
private async Task <ModelConfigurationDto> CreateOrUpdateAsync(EntityConfig modelConfig, ModelConfigurationDto input) { var mapper = GetModelConfigMapper(modelConfig.Source ?? Domain.Enums.MetadataSourceType.UserDefined); mapper.Map(input, modelConfig); await _entityConfigRepository.InsertOrUpdateAsync(modelConfig); var properties = await _entityPropertyRepository.GetAll().Where(p => p.EntityConfig == modelConfig).OrderBy(p => p.SortOrder).ToListAsync(); var mappers = new Dictionary <MetadataSourceType, IMapper> { { MetadataSourceType.ApplicationCode, GetPropertyMapper(MetadataSourceType.ApplicationCode) }, { MetadataSourceType.UserDefined, GetPropertyMapper(MetadataSourceType.UserDefined) }, }; await BindProperties(mappers, properties, input.Properties, modelConfig, null); // delete missing properties var allPropertiesId = new List <Guid>(); ActionPropertiesRecursive(input.Properties, prop => { var id = prop.Id.ToGuidOrNull(); if (id != null) { allPropertiesId.Add(id.Value); } }); var toDelete = properties.Where(p => !allPropertiesId.Contains(p.Id)).ToList(); foreach (var prop in toDelete) { await _entityPropertyRepository.DeleteAsync(prop); } return(await _modelConfigurationProvider.GetModelConfigurationAsync(modelConfig)); }