コード例 #1
0
        public async Task <ActionResult> Delete(string repoId)
        {
            var repository = await _assetRepoCoordinator.GetRepository(repoId);

            if (repository == null)
            {
                return(RedirectToAction("Index"));
            }

            var model = new DeleteStorageModel(repository);

            try
            {
                var sudId  = repository.SubscriptionId.ToString();
                var mapped = new List <GenericResource>();
                if (!string.IsNullOrEmpty(repository.ResourceGroupName))
                {
                    var resources = await _azureResourceProvider.ListResourceGroupResources(sudId, repository.ResourceGroupName);

                    mapped.AddRange(resources.Select(resource => new GenericResource(resource)));
                }

                model.Resources.AddRange(mapped);
            }
            catch (CloudException ex)
            {
                if (!ex.ResourceNotFound())
                {
                    model.ResourceLoadFailed = true;
                }
                ModelState.AddModelError("", $"Failed to list resources from the Resource Group with error: {ex.Message}");
            }

            return(View("View/Delete", model));
        }
コード例 #2
0
        public async Task <ActionResult> Delete(string repoId, DeleteStorageModel model)
        {
            if (!model.Name.Equals(model.Confirmation, StringComparison.OrdinalIgnoreCase))
            {
                ModelState.AddModelError(nameof(DeleteStorageModel.Confirmation),
                                         $"The entered name must match '{model.Name}'");
            }

            if (!model.SubscriptionId.HasValue)
            {
                ModelState.AddModelError("", "Storage does not have a configured subscription ID. Deletion cannot continue.");
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var repository = await _assetRepoCoordinator.GetRepository(repoId);

            if (repository == null)
            {
                return(RedirectToAction("Index"));
            }

            await _assetRepoCoordinator.BeginDeleteRepositoryAsync(repository, model.DeleteResourceGroup);

            return(RedirectToAction("Deleting", new { repoId }));
        }