Exemple #1
0
        public async Task <IActionResult> Edit(ApiScopeModel model)
        {
            if (model.Id == 0)
            {
                return(RedirectToAction(nameof(Index)));
            }

            var apiScope = await _apiScopeService.GetApiScopeByIdAsync(model.Id);

            if (apiScope == null)
            {
                return(RedirectToAction(nameof(Index)));
            }

            model.UserClaims = model.UserClaimsItems.Deserialize <List <string> >()?.Select(x => new ApiScopeClaimModel()
            {
                Type = x
            }).ToList();

            apiScope = CommonMappers.Mapper.Map <ApiScope>(model);

            var updatedResult = await _apiScopeService.UpdateApiScopeAsync(apiScope);

            if (updatedResult)
            {
                SuccessNotification(await _localizationService.GetResourceAsync("ApiResource.Updated"));

                return(RedirectToAction(nameof(Index)));
            }

            return(View(model));
        }
        public async Task <IActionResult> ApiScope(ApiScopeDto apiScope)
        {
            if (!ModelState.IsValid)
            {
                return(View(apiScope));
            }

            _apiScopeService.BuildApiScopeViewModel(apiScope);

            int apiScopeId;

            if (apiScope.Id == 0)
            {
                apiScopeId = await _apiScopeService.AddApiScopeAsync(apiScope);
            }
            else
            {
                apiScopeId = apiScope.Id;
                await _apiScopeService.UpdateApiScopeAsync(apiScope);
            }

            SuccessNotification(string.Format(_localizer["SuccessAddApiScope"], apiScope.Name), _localizer["SuccessTitle"]);

            return(RedirectToAction(nameof(ApiScope), new { Scope = apiScopeId }));
        }