Example #1
0
        public async Task <IActionResult> NewScope(ScopeItemViewModel scopeModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("EditScope", new { siteId = scopeModel.SiteId, scopeName = scopeModel.Name }));
            }

            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);

            ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, sr["{0} - New Scope"], selectedSite.SiteName);

            var exists = await scopesManager.ScopeExists(selectedSite.Id.ToString(), scopeModel.Name);

            var scopeType = scopesManager.ResolveScopeType(scopeModel.ScopeType);

            if (exists || !scopeType.HasValue)
            {
                var model = new ScopeEditViewModel();
                model.SiteId          = selectedSite.Id.ToString();
                model.NewScope        = scopeModel;
                model.NewScope.SiteId = model.SiteId;

                if (exists)
                {
                    ModelState.AddModelError("scopenameinuseerror", sr["Scope name is already in use"]);
                }
                if (!scopeType.HasValue)
                {
                    ModelState.AddModelError("invalidscopetypeerror", sr["Invalid Scope Type"]);
                }

                return(View("EditScope", model));
            }

            var scope = new Scope
            {
                Type        = scopeType.Value,
                Name        = scopeModel.Name,
                DisplayName = scopeModel.DisplayName,
                Description = scopeModel.Description
            };

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

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

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

            return(RedirectToAction("EditScope", new { siteId = selectedSite.Id.ToString(), scopeName = scope.Name }));
        }
Example #2
0
        public async Task <IActionResult> EditScope(
            Guid?siteId,
            string scopeName = null)
        {
            var selectedSite = await siteManager.GetSiteForDataOperations(siteId);

            if (!string.IsNullOrEmpty(scopeName))
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, sr["{0} - Edit Scope"], selectedSite.SiteName);
            }

            var model = new ScopeEditViewModel();

            model.SiteId          = selectedSite.Id.ToString();
            model.NewScope.SiteId = model.SiteId;
            if (!string.IsNullOrEmpty(scopeName))
            {
                var scope = await scopesManager.FetchScope(model.SiteId, scopeName);

                model.CurrentScope = scope;
            }

            if (model.CurrentScope == null)
            {
                ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, sr["{0} - New Scope"], selectedSite.SiteName);
                var currentCrumbAdjuster = new NavigationNodeAdjuster(Request.HttpContext);
                currentCrumbAdjuster.KeyToAdjust  = "EditScope";
                currentCrumbAdjuster.AdjustedText = sr["New Scope"];
                currentCrumbAdjuster.AddToContext();
            }
            else
            {
                model.NewScopeClaim.SiteId     = model.SiteId;
                model.NewScopeClaim.ScopeName  = model.CurrentScope.Name;
                model.NewScopeSecret.SiteId    = model.SiteId;
                model.NewScopeSecret.ScopeName = model.CurrentScope.Name;
            }

            return(View(model));
        }