public IEnumerable <AuditComment> getCommentAudit(int commentId) { List <AuditComment> audit = new List <AuditComment>(); DataRowCollection data; using (IRSAPIClient proxy = _helper.GetServicesManager().CreateProxy <IRSAPIClient>(ExecutionIdentity.System)) { int workspace = _workspaceID; IDBContext dbContext = _helper.GetDBContext(workspace); string sql = $@"SELECT TOP (1000) [ArtifactId] ,[CommentId] ,[CreatedOn] ,[CreateByUserId] ,[CreatedByUserName] ,[ModifiedOn] ,[ModifiedByUserId] ,[ModifiedByUserName] ,[ReplysAmount] ,[comment] ,[type] FROM [EDDSDBO].[AuditComment] WHERE [CommentId] ={commentId};"; data = dbContext.ExecuteSqlStatementAsDataTable(sql).Rows; foreach (DataRow item in data) { AuditComment commentAudit = new AuditComment(); commentAudit.commentId = (int)item.ItemArray[1]; commentAudit.createdOn = (item.ItemArray[2]).ToString(); commentAudit.createByUserId = commentAudit.createdOn == string.Empty ? 0 : (int)item.ItemArray[3]; commentAudit.createdByUserName = commentAudit.createdOn == string.Empty ? "" : (string)item.ItemArray[4]; commentAudit.modifiedOn = (item.ItemArray[5]).ToString(); commentAudit.modifiedByUserId = commentAudit.createdOn == string.Empty ? (int)item.ItemArray[6] : 0; commentAudit.modifiedByUserName = commentAudit.createdOn == string.Empty ? (string)item.ItemArray[7] : ""; commentAudit.replysAmount = (int)item.ItemArray[8]; commentAudit.comment = (string)item.ItemArray[9]; commentAudit.type = (string)item.ItemArray[10]; audit.Add(commentAudit); } } return(audit); }
public async Task <IHttpActionResult> AddComment(string name, Guid deploymentAuditId, [FromBody] AuditComment auditComment) { try { if (string.IsNullOrWhiteSpace(auditComment?.Comment)) { return(BadRequest("The body is not valid. You must include a comment.")); } var getAppTask = applicationRepository.GetApplicationAsync(name); var getAuditTask = auditRepository.GetAuditsAsync(new[] { deploymentAuditId }); await Task.WhenAll(getAppTask, getAuditTask); var application = getAppTask.Result; var audit = getAuditTask.Result.FirstOrDefault(); if (application == null) { return(BadRequest("Unknown application name: `" + name + "`.")); } if (audit == null) { return(NotFound()); } var newComments = new List <AuditComment>(audit.Comments); newComments.Add(auditComment); await auditRepository.UpdateCommentsAsync(audit.DeploymentAuditId, newComments); return(Ok()); } catch (Exception ex) { Log.Error("Error in audit controller:", ex); return(InternalServerError()); } }