public async Task SeedAsync(DataSeedContext context) { /* Instead of returning the Task.CompletedTask, you can insert your test data * at this point! */ var fdName = new FieldDefinition(DynamicEntityTestConsts.FieldDefinitionNameId, "name", "Name", FieldDataType.Text); await _fieldDefinitionRepository.InsertAsync(fdName); var fdPrice = new FieldDefinition(DynamicEntityTestConsts.FieldDefinitionPriceId, "price", "Price", FieldDataType.Number); await _fieldDefinitionRepository.InsertAsync(fdPrice); var mdBook = new ModelDefinition(DynamicEntityTestConsts.ModelDefinitionBookId, "book", "Book", "DynamicEntity.Book", new PermissionSetValueObject()); mdBook.AddField(fdPrice, 2); mdBook.AddField(fdName, 1); await _modelDefinitionRepository.InsertAsync(mdBook); var deBook1 = new DynamicEntities.DynamicEntity(DynamicEntityTestConsts.DynamicEntityBook1Id, context.TenantId, mdBook.Id); deBook1.SetProperty("name", "Book1"); deBook1.SetProperty("price", 100.00f); await _dynamicEntityRepository.InsertAsync(deBook1); var deBook2 = new DynamicEntities.DynamicEntity(DynamicEntityTestConsts.DynamicEntityBook2Id, context.TenantId, mdBook.Id); deBook2.SetProperty("name", "Book2"); deBook2.SetProperty("price", 200.00f); await _dynamicEntityRepository.InsertAsync(deBook2); }
public async Task SeedAsync(DataSeedContext context) { /* Instead of returning the Task.CompletedTask, you can insert your test data * at this point! */ var fdName = new FieldDefinition(_guidGenerator.Create(), "name", "Name", "string"); await _fieldDefinitionRepository.InsertAsync(fdName); var fdPrice = new FieldDefinition(_guidGenerator.Create(), "price", "Price", "number"); await _fieldDefinitionRepository.InsertAsync(fdPrice); var mdBook = new ModelDefinition(_guidGenerator.Create(), "book", "Book", "DynamicEntity.Book"); mdBook.AddField(fdPrice.Id, 2); mdBook.AddField(fdName.Id, 1); await _modelDefinitionRepository.InsertAsync(mdBook); var deBook1 = new DynamicEntities.DynamicEntity(_guidGenerator.Create()); deBook1.SetModelDefinition(mdBook.Id); deBook1.SetProperty("name", "Book1"); deBook1.SetProperty("price", 100.00f); await _dynamicEntityRepository.InsertAsync(deBook1); var deBook2 = new DynamicEntities.DynamicEntity(_guidGenerator.Create()); deBook2.SetModelDefinition(mdBook.Id); deBook2.SetProperty("name", "Book2"); deBook2.SetProperty("price", 200.00f); await _dynamicEntityRepository.InsertAsync(deBook2); }
public async Task SeedAsync(DataSeedContext context) { var fdPrice = await _fieldDefinitionRepository.FindAsync(fd => fd.Name == "price"); if (fdPrice == null) { fdPrice = await _fieldDefinitionRepository.InsertAsync(new FieldDefinition(_guidGenerator.Create(), "price", "Price", "number")); } var fdCpu = await _fieldDefinitionRepository.FindAsync(fd => fd.Name == "CPU"); if (fdCpu == null) { fdCpu = await _fieldDefinitionRepository.InsertAsync(new FieldDefinition(_guidGenerator.Create(), "cpu", "CPU", "string")); } var fdRam = await _fieldDefinitionRepository.FindAsync(fd => fd.Name == "ram"); if (fdRam == null) { fdRam = await _fieldDefinitionRepository.InsertAsync(new FieldDefinition(_guidGenerator.Create(), "ram", "RAM", "string")); } var mdComputer = await _modelDefinitionRepository.FindAsync(md => md.Name == "computer"); if (mdComputer == null) { mdComputer = new ModelDefinition(_guidGenerator.Create(), "computer", "Computer", "DynamicEntitySample.Computer"); mdComputer.AddField(fdCpu.Id, 1); mdComputer.AddField(fdRam.Id, 2); mdComputer.AddField(fdPrice.Id, 3); await _modelDefinitionRepository.InsertAsync(mdComputer); } var deComputer = await _dynamicEntityRepository.FindAsync(de => de.ModelDefinitionId == mdComputer.Id); if (deComputer == null) { var cpus = new[] { "Intel I3", "Intel I5", "Intel I7", "Intel I9" }; var rams = new[] { "4GB", "8GB", "16GB", "32GB" }; var prices = new[] { "999", "1999", "2999", "3999" }; var rnd = new Random(); for (int i = 0; i < 30000; i++) { var entity = new DynamicEntity(_guidGenerator.Create()).SetModelDefinition(mdComputer.Id); entity.SetProperty("cpu", cpus[rnd.Next() % cpus.Length]); entity.SetProperty("ram", rams[rnd.Next() % rams.Length]); entity.SetProperty("price", prices[rnd.Next() % prices.Length]); await _dynamicEntityRepository.InsertAsync(entity); } } }
public override async Task <DynamicEntityDto> CreateAsync(CreateDynamicEntityDto input) { var entity = new DynamicEntity(GuidGenerator.Create(), CurrentTenant.Id, input.ModelDefinitionId); var modelDefinition = await GetModelDefinitionAsync(entity.ModelDefinitionId); foreach (var extraProperty in input.ExtraProperties.Where(x => modelDefinition.Fields.Select(y => y.FieldDefinition.Name.ToCamelCase()).Contains(x.Key.ToCamelCase()))) { entity.SetProperty(extraProperty.Key, extraProperty.Value); } await AuthorizationService.CheckAsync(new DynamicEntityOperationInfoModel(modelDefinition, entity), new DynamicEntityOperationAuthorizationRequirement(DynamicEntityOperationAuthorizationRequirement .CreateName)); await _repository.InsertAsync(entity, true); return(await MapToGetOutputDtoAsync(entity)); }
public async Task SeedAsync(DataSeedContext context) { var fdPrice = await _fieldDefinitionRepository.FindAsync(fd => fd.Name == "Price"); if (fdPrice == null) { fdPrice = await _fieldDefinitionRepository.InsertAsync(new FieldDefinition(_guidGenerator.Create(), "Price", "Price", FieldDataType.Number)); } var fdCpu = await _fieldDefinitionRepository.FindAsync(fd => fd.Name == "Cpu"); if (fdCpu == null) { fdCpu = await _fieldDefinitionRepository.InsertAsync(new FieldDefinition(_guidGenerator.Create(), "Cpu", "Cpu", FieldDataType.Text)); } var fdRam = await _fieldDefinitionRepository.FindAsync(fd => fd.Name == "Ram"); if (fdRam == null) { fdRam = await _fieldDefinitionRepository.InsertAsync(new FieldDefinition(_guidGenerator.Create(), "Ram", "Ram", FieldDataType.Text)); } var mdComputer = await _modelDefinitionRepository.FindAsync(md => md.Name == "Computer"); if (mdComputer == null) { const string permissionPrefix = DynamicEntityConsts.DynamicPermissionPrefix; var permissionSet = new PermissionSetValueObject( get: (await GetOrCreatePermissionAsync($"{permissionPrefix}.Computer")).Name, getList: (await GetOrCreatePermissionAsync($"{permissionPrefix}.Computer")).Name, create: (await GetOrCreatePermissionAsync($"{permissionPrefix}.Computer.Create")).Name, update: (await GetOrCreatePermissionAsync($"{permissionPrefix}.Computer.Update")).Name, delete: (await GetOrCreatePermissionAsync($"{permissionPrefix}.Computer.Delete")).Name ); mdComputer = new ModelDefinition(_guidGenerator.Create(), "Computer", "Computer", "DynamicEntitySample.Computer", permissionSet); mdComputer.AddField(fdCpu, 1); mdComputer.AddField(fdRam, 2); mdComputer.AddField(fdPrice, 3); await _modelDefinitionRepository.InsertAsync(mdComputer); } var deComputer = await _dynamicEntityRepository.FirstOrDefaultAsync(de => de.ModelDefinitionId == mdComputer.Id); if (deComputer == null) { var cpus = new[] { "Intel I3", "Intel I5", "Intel I7", "Intel I9" }; var rams = new[] { "4GB", "8GB", "16GB", "32GB" }; var prices = new[] { "999", "1999", "2999", "3999" }; var rnd = new Random(); for (int i = 0; i < 300; i++) { var entity = new DynamicEntity(_guidGenerator.Create(), context.TenantId, mdComputer.Id); entity.SetProperty("Cpu", cpus[rnd.Next() % cpus.Length]); entity.SetProperty("Ram", rams[rnd.Next() % rams.Length]); entity.SetProperty("Price", prices[rnd.Next() % prices.Length]); await _dynamicEntityRepository.InsertAsync(entity); } } }