public async Task AddSandboxAsync(string sandboxKey, SandboxType sandboxType)
        {
            await DeleteSandboxesAsync(sandboxKey).ConfigureAwait(false);

            switch (sandboxType)
            {
            case SandboxType.Minimal:
                await CopySandboxAsync(
                    _databaseNameBuilder.MinimalDatabase,
                    _databaseNameBuilder.SandboxNameForKey(sandboxKey))
                .ConfigureAwait(false);

                break;

            case SandboxType.Sample:
                await CopySandboxAsync(
                    _databaseNameBuilder.SampleDatabase,
                    _databaseNameBuilder.SandboxNameForKey(sandboxKey))
                .ConfigureAwait(false);

                break;

            default:
                throw new Exception("Unhandled SandboxType provided");
            }
        }
        private SandboxIndexViewModel GetSandboxIndexViewModel()
        {
            var users          = _clientAppRepo.GetUsers();
            var knownSandboxes = new List <SandboxViewModel>();

            foreach (var user in users)
            {
                foreach (var client in user.ApiClients)
                {
                    knownSandboxes.Add(
                        new SandboxViewModel
                    {
                        Client          = client.Name,
                        User            = user.Email,
                        ApplicationName = client.Application.ApplicationName,
                        Sandbox         = _databaseNameBuilder.SandboxNameForKey(client.Key)
                    });
                }
            }

            var sandboxDatabases = _sandboxProvisioner.GetSandboxDatabases();

            var orphans = sandboxDatabases.Where(db => knownSandboxes.All(k => k.Sandbox != db))
                          .ToArray();

            var ownedSandboxes = knownSandboxes.Where(sb => sandboxDatabases.Contains(sb.Sandbox))
                                 .ToArray();

            var missingSandboxes = knownSandboxes.Except(ownedSandboxes)
                                   .ToArray();

            var model = new SandboxIndexViewModel
            {
                AllSandboxes     = sandboxDatabases,
                OwnedSandboxes   = ownedSandboxes,
                OrphanSandboxes  = orphans,
                MissingSandboxes = missingSandboxes
            };

            return(model);
        }