public async Task <IActionResult> NewResource(IdentityItemViewModel resourceModel) { if (!ModelState.IsValid) { return(RedirectToAction("EditResource", new { siteId = resourceModel.SiteId, resourceName = resourceModel.Name })); } Guid siteId = siteManager.CurrentSite.Id; if (!string.IsNullOrEmpty(resourceModel.SiteId) && resourceModel.SiteId.Length == 36) { siteId = new Guid(resourceModel.SiteId); } var selectedSite = await siteManager.GetSiteForDataOperations(siteId); ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, sr["{0} - New Identity Resource"], selectedSite.SiteName); var exists = await idManager.IdentityResourceExists(selectedSite.Id.ToString(), resourceModel.Name); if (exists) { var model = new IdentityEditViewModel(); model.SiteId = selectedSite.Id.ToString(); model.NewResource = resourceModel; model.NewResource.SiteId = model.SiteId; if (exists) { ModelState.AddModelError("resourcenameinuseerror", sr["Identity Resource name is already in use"]); } return(View("EditResource", model)); } var identityResource = new IdentityResource { Name = resourceModel.Name, DisplayName = resourceModel.DisplayName, Description = resourceModel.Description, Enabled = resourceModel.Enabled, Required = resourceModel.Required, ShowInDiscoveryDocument = resourceModel.ShowInDiscoveryDocument }; await idManager.CreateIdentityResource(selectedSite.Id.ToString(), identityResource); var successFormat = sr["The Identity Resource <b>{0}</b> was successfully Created."]; this.AlertSuccess(string.Format(successFormat, identityResource.Name), true); return(RedirectToAction("EditResource", new { siteId = selectedSite.Id.ToString(), resourceName = identityResource.Name })); }
public async Task <IActionResult> EditResource( Guid?siteId, string resourceName = null) { var selectedSite = await siteManager.GetSiteForDataOperations(siteId); if (!string.IsNullOrEmpty(resourceName)) { ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, sr["{0} - Edit Identity Resource"], selectedSite.SiteName); } var model = new IdentityEditViewModel(); model.SiteId = selectedSite.Id.ToString(); model.NewResource.SiteId = model.SiteId; model.NewClaim.SiteId = model.SiteId; if (!string.IsNullOrEmpty(resourceName)) { var resource = await idManager.FetchIdentityResource(model.SiteId, resourceName); model.CurrentResource = resource; } if (model.CurrentResource == null) { ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, sr["{0} - New Identity Resource"], selectedSite.SiteName); var currentCrumbAdjuster = new NavigationNodeAdjuster(Request.HttpContext); currentCrumbAdjuster.KeyToAdjust = "EditIdentityResource"; currentCrumbAdjuster.AdjustedText = sr["New Identity Resource"]; currentCrumbAdjuster.AddToContext(); } else { model.NewClaim.SiteId = model.SiteId; model.NewClaim.ResourceName = model.CurrentResource.Name; } return(View(model)); }