public async Task <IActionResult> CreateScope(
            [FromRoute] string id,
            [FromForm] CreateScopeViewModel model)
        {
            var application = await _applicationManager.FindByIdAsync(id);

            var applicationName = await _applicationManager.GetApplicationNameAsync(application);

            var scopes = await _applicationManager.FindScopesAsync(application);

            if (!ModelState.IsValid)
            {
                return(View(new CreateScopeViewModel(applicationName, scopes)));
            }

            var result = await _applicationManager.AddScopeAsync(application, model.NewScope);

            if (!result.Succeeded)
            {
                MapErrorsToModelState("", result);
                return(View(new CreateScopeViewModel(applicationName, scopes)));
            }

            return(RedirectToAction(nameof(CreateScope), new { id }));
        }
Exemple #2
0
        //[Authorize]
        public async Task <IActionResult> Create([FromBody] CreateScopeViewModel viewModel)
        {
            var scopeDTO = _mapper.Map <ScopeDTO>(viewModel);
            var response = await _scopeService.Create(scopeDTO);

            return(StatusCode(response.StatusCode, response.Data));
        }
        public IActionResult CreateScope(int clientId)
        {
            var model = new CreateScopeViewModel {
                ClientId = clientId
            };

            return(View(model));
        }
        public IActionResult CreateScope(CreateScopeViewModel model)
        {
            var entity = model.ToEntity();

            var client = _configurationDbContext.Clients.Include(c => c.AllowedScopes).Single(c => c.Id == model.ClientId);

            client.AllowedScopes.Add(entity);
            _configurationDbContext.SaveChanges();

            return(RedirectToAction(nameof(Edit), new { id = model.ClientId }));
        }
 public static ClientScope ToEntity(this CreateScopeViewModel model)
 {
     return(Mapper.Map <ClientScope>(model));
 }