public async Task CreateOrUpdateCredentialAsync(EmailConnectorCredential credential) { using (var ctx = new EmailServiceDbEntities(this.connectionString)) { var entity = await ctx.ConnectorCredentials.SingleOrDefaultAsync( c => c.Provider == credential.ConnectorName && c.Id == credential.ConnectorId); if (entity == null) { entity = new ConnectorCredentialEntity(); entity.Provider = credential.ConnectorName; entity.Id = credential.ConnectorId; entity.Data = JsonConvert.SerializeObject(credential); entity.Created = entity.Modified = DateTime.UtcNow; entity.Enabled = true; ctx.ConnectorCredentials.Add(entity); } else { entity.Data = JsonConvert.SerializeObject(credential); entity.Modified = DateTime.UtcNow; entity.Enabled = true; } await ctx.SaveChangesAsync(); } }
public Credential(EmailConnectorCredential connectorCredential) { this.ConnectorName = connectorCredential.ConnectorName; this.ConnectorKey = connectorCredential.ConnectorId; this.ConnectorProperties = new PropertyCollection <string>(connectorCredential.ConnectorProperties); }