public ScopeEditViewModel()
 {
     NewScope = new ScopeItemViewModel();
     NewScopeClaim = new NewScopeClaimViewModel();
     NewScopeSecret = new NewScopeSecretViewModel();
 }
        public async Task<IActionResult> AddScopeClaim(NewScopeClaimViewModel scopeModel)
        {
            if (!ModelState.IsValid)
            {
                return RedirectToAction("EditScope", new { siteId = scopeModel.SiteId, scopeName = scopeModel.ScopeName });
            }

            Guid siteId = siteManager.CurrentSite.Id;
            if (!string.IsNullOrEmpty(scopeModel.SiteId) && scopeModel.SiteId.Length == 36)
            {
                siteId = new Guid(scopeModel.SiteId);
            }
            var selectedSite = await siteManager.GetSiteForDataOperations(siteId);

            var scope = await scopesManager.FetchScope(selectedSite.Id.ToString(), scopeModel.ScopeName);
            if(scope == null)
            {
                this.AlertDanger(sr["Invalid request, scope not found."], true);
                return RedirectToAction("Index");
            }

            var claim = new ScopeClaim(scopeModel.Name, scopeModel.AlwaysIncludeInIdToken);
            claim.Description = scopeModel.Description;

            if(scope.Claims.Contains(claim))
            {
                this.AlertDanger(sr["Scope already has a claim with that name."], true);
                return RedirectToAction("EditScope", new { siteId = selectedSite.Id.ToString(), scopeName = scopeModel.ScopeName });
            }
            scope.Claims.Add(claim);

            await scopesManager.UpdateScope(selectedSite.Id.ToString(), scope);

            var successFormat = sr["The Claim <b>{0}</b> was successfully added."];

            this.AlertSuccess(string.Format(successFormat, claim.Name), true);

            return RedirectToAction("EditScope", new { siteId = selectedSite.Id.ToString(), scopeName = scopeModel.ScopeName });
        }
 public ScopeEditViewModel()
 {
     NewScope       = new ScopeItemViewModel();
     NewScopeClaim  = new NewScopeClaimViewModel();
     NewScopeSecret = new NewScopeSecretViewModel();
 }