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)); } 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 })); }
public async Task <IActionResult> EditApiResource( Guid?siteId, string apiName = null) { var selectedSite = await _siteManager.GetSiteForDataOperations(siteId); if (!string.IsNullOrEmpty(apiName)) { ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, sr["{0} - Edit API Resource"], selectedSite.SiteName); } var model = new ApiEditViewModel(); model.SiteId = selectedSite.Id.ToString(); model.NewApi.SiteId = model.SiteId; if (!string.IsNullOrEmpty(apiName)) { var apiResource = await _apiManager.FetchApiResource(model.SiteId, apiName); model.CurrentApi = apiResource; } if (model.CurrentApi == null) { ViewData["Title"] = string.Format(CultureInfo.CurrentUICulture, sr["{0} - New API Resource"], selectedSite.SiteName); var currentCrumbAdjuster = new NavigationNodeAdjuster(Request.HttpContext); currentCrumbAdjuster.KeyToAdjust = "EditApiResource"; currentCrumbAdjuster.AdjustedText = sr["New API Resource"]; currentCrumbAdjuster.AddToContext(); } else { model.NewApiClaim.SiteId = model.SiteId; model.NewApiClaim.ApiName = model.CurrentApi.Name; model.NewApiSecret.SiteId = model.SiteId; model.NewApiSecret.ApiName = model.CurrentApi.Name; model.NewScope.SiteId = model.SiteId; model.NewScope.ApiName = model.CurrentApi.Name; } return(View(model)); }