Example #1
0
        public override void CheckForChanges()
        {
            if (HasUnsavedChanges)
            {
                return;
            }

            if (ApiKeys.Count != OriginalApiKeys.Count)
            {
                HasUnsavedChanges = true;
                return;
            }

            foreach (var apiKeyDefinition in ApiKeys)
            {
                var original = OriginalApiKeys.FirstOrDefault(definition => definition.Name == apiKeyDefinition.Name);

                HasUnsavedChanges = apiKeyDefinition.Equals(original) == false;

                if (HasUnsavedChanges)
                {
                    return;
                }
            }
        }
Example #2
0
        private void SaveApiKeys()
        {
            var session = ApplicationModel.Current.Server.Value.DocumentStore.OpenAsyncSession();

            var apiKeysToDelete = OriginalApiKeys
                                  .Where(apiKeyDefinition => ApiKeys.Contains(apiKeyDefinition) == false)
                                  .ToList();

            foreach (var apiKeyDefinition in apiKeysToDelete)
            {
                DatabaseCommands.ForDefaultDatabase().DeleteDocumentAsync(apiKeyDefinition.Id);
            }

            foreach (var apiKeyDefinition in ApiKeys)
            {
                apiKeyDefinition.Id = "Raven/ApiKeys/" + apiKeyDefinition.Name;
                //apiKeyDefinition.Secret = Convert.ToBase64String(Encoding.UTF8.GetBytes(apiKeyDefinition.Secret));
                session.Store(apiKeyDefinition);
            }

            session.SaveChangesAsync();
            ApiKeys = new ObservableCollection <ApiKeyDefinition>(ApiKeys);
            OnPropertyChanged(() => ApiKeys);
            ApplicationModel.Current.AddInfoNotification("Api Keys Saved");
        }