public static bool SaveCredential(Credential credential) { bool result = _database.SaveCredential(credential); if (result && _credentials.Contains(credential) == false) _credentials.Add(credential); return result; }
public override void ViewDidLoad() { base.ViewDidLoad (); // Perform any additional setup after loading the view, typically from a nib. if ( NavigationController != null ) { NavigationController.NavigationBarHidden = false; } if ( ActiveCredential == null ) { this.Title = "Add Credential"; ActiveCredential = new Credential(); } else { this.Title = ActiveCredential.Name; } }
public List<Credential> GetCredentials() { List<Credential> credentials = new List<Credential>(); if ( _connection == null ) return credentials; try { using (var command = _connection.CreateCommand()) { command.CommandType = CommandType.Text; command.CommandText = "SELECT * From Credentials"; using (var reader = command.ExecuteReader()) { while (reader.Read()) { Credential credential = new Credential(); credential.Id = reader.GetInt32(reader.GetOrdinal(CredentialFields.Id)); credential.Name = reader.GetValue(reader.GetOrdinal(CredentialFields.Name)) as string; credential.Notes = reader.GetValue(reader.GetOrdinal(CredentialFields.Notes)) as string; credential.Password = reader.GetValue(reader.GetOrdinal(CredentialFields.Password)) as string; credential.Username = reader.GetValue(reader.GetOrdinal(CredentialFields.Username)) as string; credential.Url = reader.GetValue(reader.GetOrdinal(CredentialFields.Url)) as string; credentials.Add(credential); } } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); } return credentials; }
public static void ShowCredentialDetails(Credential credential, UIViewController controller, UITableView tableView) { bool isNew = credential.Id == 0; var binding = new BindingContext(null, credential, isNew ? "Add Credential" : credential.Name); var dialogViewController = new DialogViewController(binding.Root); if ( controller is UINavigationController ) { var navController = (controller as UINavigationController); navController.PushViewController(dialogViewController, true); navController.NavigationBarHidden = false; UIBarButtonItem addButton = new UIBarButtonItem (UIBarButtonSystemItem.Save); dialogViewController.NavigationItem.HidesBackButton = false; dialogViewController.NavigationItem.RightBarButtonItem = addButton; addButton.Clicked += (sender, e) => { binding.Fetch(); binding.Root.Caption = credential.Name; if (ClientInterface.SaveCredential(credential) && tableView != null) { tableView.ReloadData(); } navController.PopViewControllerAnimated(true); }; } else { controller.PresentModalViewController(dialogViewController, true); } }
public bool SaveCredential(Credential credential) { if ( _connection == null ) return false; try { using (var command = _connection.CreateCommand()) { command.CommandType = CommandType.Text; if (credential.Id == 0 ) { command.CommandText = string.Format("INSERT INTO Credentials (Name, Notes, Password, Username, Url) VALUES ('{0}','{1}','{2}','{3}','{4}'); select last_insert_rowid()", credential.Name, credential.Notes, credential.Password, credential.Username, credential.Url); var id = command.ExecuteScalar(); credential.Id = int.Parse(id.ToString()); } else { command.CommandText = string.Format("UPDATE Credentials SET Name = '{0}', Notes ='{1}', Password = '******', Username = '******', Url = '{4}' WHERE Id = {5}", credential.Name, credential.Notes, credential.Password, credential.Username, credential.Url, credential.Id); command.ExecuteNonQuery(); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.Message); return false; } return true; }
public CredentialDetailViewController(Credential credential) : base("CredentialDetailViewController", null) { ActiveCredential = credential; }
public static void DeleteCredential(Credential credential) { }
public static void ShowCredentialDetails(Credential credential, UIViewController controller) { ShowCredentialDetails(credential, controller, null); }