/// <summary> /// Update SugarCrmCredential object. /// </summary> /// <param name="sugarCrmCredential">SugarCrmCredential object.</param> private void UpdateCredntial(SugarCrmCredential sugarCrmCredential) { _currentSugarCrmAccount.Username = string.Empty; _currentSugarCrmAccount.Password = string.Empty; if ((sugarCrmCredential != null) && sugarCrmCredential.IsValid) { _currentSugarCrmAccount.Username = sugarCrmCredential.Username; _currentSugarCrmAccount.Password = sugarCrmCredential.Password; } _eventAggregator.GetEvent <AccountMessage>().Publish(_currentSugarCrmAccount); }
/// <summary> /// Adds SugarCrmCredential object to the credential list. /// </summary> /// <param name="credential">The SugarCrmCredential object to add.</param> public void AddCredntial(SugarCrmCredential credential) { if (credential == null || !credential.IsValid) { return; } var credentialAlreadyAdded = _sugarCrmCredentialList.FirstOrDefault( x => string.Equals(x.Name, credential.Name, StringComparison.OrdinalIgnoreCase)); if (credentialAlreadyAdded == null) { _sugarCrmCredentialList.Add(credential); string jsonCreds = JsonConvert.SerializeObject(_sugarCrmCredentialList); File.WriteAllText(SugarCrmCredentialsFile, jsonCreds); } }
/// <summary> /// Removes specified SugarCrmCredential object identified by url name. /// </summary> /// <param name="credential">The SugarCrmCredential object to remove.</param> /// <returns>True or false (true - success, false - failure)</returns> public bool RemoveCredntial(SugarCrmCredential credential) { if (credential == null || !credential.IsValid) { return(false); } credential = _sugarCrmCredentialList.FirstOrDefault(x => x.Equals(credential)); if (credential != null) { bool result = _sugarCrmCredentialList.Remove(credential); string jsonCreds = JsonConvert.SerializeObject(_sugarCrmCredentialList); File.WriteAllText(SugarCrmCredentialsFile, jsonCreds); return(result); } return(false); }
/// <summary> /// Add credential function. /// </summary> /// <param name="parameter">The command parameter.</param> private void AddCredential(object parameter) { var addCredentialViewModel = new AddCredentialViewModel(UrlItems, UrlItemSelected); var dlg = new ModernDialog { Title = "Add Credential", Content = new AddCredentialContent(addCredentialViewModel) }; dlg.Buttons = new[] { dlg.OkButton, dlg.CancelButton }; dlg.ShowDialog(); if (dlg.MessageBoxResult == MessageBoxResult.OK) { var name = addCredentialViewModel.Name; var username = addCredentialViewModel.Username; var password = addCredentialViewModel.Password; var sugarCrmCredential = new SugarCrmCredential { Name = name, Username = username, Password = password }; if (sugarCrmCredential.IsValid) { SugarCrmAccountService.Instance.AddCredntial(sugarCrmCredential); } if ((CredentialItemSelected == null) || !CredentialItemSelected.SameUrlGroup(sugarCrmCredential)) { CredentialItemSelected = sugarCrmCredential; Username = CredentialItemSelected.Username; Password = CredentialItemSelected.Password; UpdateCredntial(CredentialItemSelected); } } }