public async Task<QueryResult> AddContact(Contact contact, CancellationToken cancellationToken) { Handle(cancellationToken); if (contact == null) throw new ArgumentNullException(nameof(contact)); if (string.IsNullOrEmpty(contact.Relation) || string.IsNullOrEmpty(contact.Id) || string.IsNullOrEmpty(contact.Target.Id)) throw new InvalidOperationException(nameof(contact)); var count = await Connection.ExecuteAsync($"INSERT INTO {Table}(Id, Relation, Target) VALUES(@Id, @Relation, @Target)", new { contact.Id, contact.Relation, Target = contact.Target.Id }); return QueryResult.Success(count); }
public async Task<QueryResult> UpdateContact(Contact contact, CancellationToken cancellationToken) { Handle(cancellationToken); if (contact == null) throw new ArgumentNullException(nameof(contact)); if (string.IsNullOrEmpty(contact.Id) || string.IsNullOrEmpty(contact.Target.Id)) throw new InvalidOperationException(nameof(contact)); var count = await Connection.ExecuteAsync($"UPDATE {Table} SET Relation=@Relation WHERE Target=@Target AND Id=@Id", new { contact.Id, contact.Relation, Target = contact.Target.Id }); return QueryResult.Success(count); }
public async Task<Contact> FindContactByTarget(Contact contact, CancellationToken cancellationToken) { Handle(cancellationToken); if (contact == null) throw new ArgumentNullException(nameof(contact)); if (string.IsNullOrEmpty(contact.Id) || string.IsNullOrEmpty(contact.Target.Id)) throw new InvalidOperationException(nameof(contact)); var contacts = await Connection.QueryAsync($"SELECT * FROM {Table} WHERE Id=@Id AND Target=@Target", new { contact.Id, Target = contact.Target.Id }); return contacts.Select(p => new Contact { Id = p.Id, Relation = p.Relation, Target = SigmaUser.Create(p.Target) }).FirstOrDefault(); }
public async Task<QueryResult> DeleteContactByTarget(Contact contact, CancellationToken cancellationToken) { Handle(cancellationToken); if (contact == null) throw new ArgumentNullException(nameof(contact)); if (string.IsNullOrEmpty(contact.Id) || string.IsNullOrEmpty(contact.Target.Id)) throw new InvalidOperationException(nameof(contact)); var count = await Connection.ExecuteAsync($"DELETE FROM {Table} WHERE Id=@Id AND Target=@Target", new { contact.Id, Target = contact.Target.Id }); return QueryResult.Success(count); }