public async Task <string> CreateAsync(ScopeViewModel model) { if (model is null) { throw new System.ArgumentNullException(nameof(model)); } var apiScope = new ApiScope { Enabled = model.Enabled, Name = model.Name, DisplayName = model.DisplayName, Description = model.Description, Required = model.Required, ShowInDiscoveryDocument = model.ShowInDiscoveryDocument, Emphasize = model.Emphasize, }; HandleCollectionProperties(model, apiScope); this.context.ApiScopes.Add(apiScope); await this.context.SaveChangesAsync(); return(apiScope.Name); }
public async Task UpdateAsync(ScopeViewModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var apiScope = await this.GetApiScopeId(model.Id.Value); if (apiScope == null) { throw new ArgumentNullException(nameof(apiScope)); } apiScope.Enabled = model.Enabled; apiScope.Name = model.Name; apiScope.DisplayName = model.DisplayName; apiScope.Description = model.Description; apiScope.Required = model.Required; apiScope.ShowInDiscoveryDocument = model.ShowInDiscoveryDocument; apiScope.Emphasize = model.Emphasize; HandleCollectionProperties(model, apiScope); this.context.ApiScopes.Update(apiScope); await this.context.SaveChangesAsync(); }
public async Task <IActionResult> UpdateAsync([FromBody] ScopeViewModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await this.service.UpdateAsync(model); return(NoContent()); }
public async Task <IActionResult> CreateAsync([FromBody] ScopeViewModel model) { if (model == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var result = await this.service.CreateAsync(model); return(Created($"api/scopes/{result}", this.Json(result))); }
private void HandleCollectionProperties(ScopeViewModel model, ApiScope apiScope) { // deassign them if (apiScope.UserClaims != null) { apiScope.UserClaims.Clear(); } // assign them apiScope.UserClaims = model.UserClaims .Select(x => new ApiScopeClaim { Scope = apiScope, Type = x }).ToList(); }