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> NewApiResource(ApiItemViewModel apiModel) { if (!ModelState.IsValid) { return(RedirectToAction("EditApiResource", new { siteId = apiModel.SiteId, ame = apiModel.Name })); } Guid siteId = _siteManager.CurrentSite.Id; if (!string.IsNullOrEmpty(apiModel.SiteId) && apiModel.SiteId.Length == 36) { siteId = new Guid(apiModel.SiteId); } var selectedSite = await _siteManager.GetSiteForDataOperations(siteId); ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, sr["{0} - New API Resource"], selectedSite.SiteName); var exists = await _apiManager.ApiResourceExists(selectedSite.Id.ToString(), apiModel.Name); if (exists) { var model = new ApiEditViewModel(); model.SiteId = selectedSite.Id.ToString(); model.NewApi = apiModel; model.NewApi.SiteId = model.SiteId; if (exists) { ModelState.AddModelError("apinameinuseerror", sr["API Resource name is already in use"]); } return(View("EditApiResource", model)); } exists = await _idManager.IdentityResourceExists(selectedSite.Id.ToString(), apiModel.Name); if (exists) { var model = new ApiEditViewModel(); model.SiteId = selectedSite.Id.ToString(); model.NewApi = apiModel; model.NewApi.SiteId = model.SiteId; if (exists) { ModelState.AddModelError("apinameinuseerror", sr["Sorry, there already exists an Identity resource with this name, it is not allowed to have API resources with the same names as Identity resources"]); } return(View("EditApiResource", model)); } var api = new ApiResource { Name = apiModel.Name, DisplayName = apiModel.DisplayName, Description = apiModel.Description }; await _apiManager.CreateApiResource(selectedSite.Id.ToString(), api); var successFormat = sr["The API Resource <b>{0}</b> was successfully created."]; this.AlertSuccess(string.Format(successFormat, api.Name), true); return(RedirectToAction("EditApiResource", new { siteId = selectedSite.Id.ToString(), apiName = api.Name })); }