public async Task UpdateProjectAsync(BuildProjectConfiguration project) { this.EnsureOpenConnection(); var projectData = new DbProjectRecord(project); using (var transaction = this.Connection.BeginTransaction()) { await this.Connection.UpdateAsync(projectData, transaction); if (project.Contacts == null || project.Contacts.Count == 0) { await this.Connection.ExecuteAsync("DELETE FROM ProjectContact WHERE ProjectID=@ProjectID", transaction : transaction, param : new { ProjectID = project.ProjectID }); } transaction.Commit(); } }
public async Task AddProjectAsync(BuildProjectConfiguration project) { this.EnsureOpenConnection(); var projectData = new DbProjectRecord(project); using (var transaction = this.Connection.BeginTransaction()) { await this.Connection.InsertAsync(projectData, transaction); if (project.Contacts != null && project.Contacts.Count() > 0) { foreach (var contact in project.Contacts) { await this.Connection.InsertAsync(new DbProjectContactRecord(projectData.ProjectID, contact), transaction); } } if (project.AssetPaths != null && project.AssetPaths.Count() > 0) { foreach (var asset in project.AssetPaths) { await this.Connection.InsertAsync(new DbProjectAssetRecord(projectData.ProjectID, asset), transaction); } } if (project.RepositorySettings != null) { foreach (var keyPair in project.RepositorySettings) { await this.Connection.InsertAsync(new DbProjectSettingRecord() { ProjectID = projectData.ProjectID, TypeName = "Repository", Name = keyPair.Key, Value = keyPair.Value }, transaction); } } if (project.Variables != null) { foreach (var keyPair in project.Variables) { await this.Connection.InsertAsync(new DbProjectSettingRecord() { ProjectID = projectData.ProjectID, TypeName = "Variable", Name = keyPair.Key, Value = keyPair.Value }, transaction); } } if (project.Tasks != null) { for (int taskNo = 1; taskNo <= project.Tasks.Count; taskNo++) { await this.Connection.InsertAsync(new DbProjectTaskRecord(projectData.ProjectID, project.Tasks[taskNo - 1], taskNo)); } } transaction.Commit(); } }