public async Task <string> CreateAsync(ScopeParam model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var entity = await _manager.FindByNameAsync(model.Name); if (entity == null) { // create new entity var newEntity = new OpenIddictEntityFrameworkCoreScope { Name = model.Name, DisplayName = model.DisplayName, Description = model.Description, }; HandleCustomProperties(model, newEntity); await _manager.CreateAsync(newEntity); return(newEntity.Id); } // update existing entity model.Id = entity.Id; await UpdateAsync(model); return(entity.Id); }
public async Task UpdateAsync(ScopeParam model) { if (string.IsNullOrWhiteSpace(model.Id)) { throw new InvalidOperationException(nameof(model.Id)); } var entity = await _manager.FindByIdAsync(model.Id); SimpleMapper.Map(model, entity); HandleCustomProperties(model, entity); await _manager.UpdateAsync(entity); }
private static void HandleCustomProperties( ScopeParam model, OpenIddictEntityFrameworkCoreScope entity ) => entity.Resources = JsonSerializer.Serialize(model.Resources);