public async Task <long> InsertDataAuditAsync(DataAuditRequest dataAudit) { var newDataAudit = new DataAuditHistory { DatabaseName = dataAudit.DatabaseName, TableName = dataAudit.TableName, ColumnName = dataAudit.ColumnName, KeyReference = dataAudit.KeyReference, OldValue = dataAudit.OldValue, NewValue = dataAudit.NewValue, DeviceTypeId = context.DeviceTypes .Where(d => d.DeviceTypeCode.Equals(dataAudit.DeviceTypeCode)) .Select(s => s.DeviceTypeId) .First(), DeviceIdentifier = dataAudit.DeviceIdentifier, CustomerId = dataAudit.CustomerId, WorkerId = dataAudit.WorkerId, PatientProfileId = dataAudit.PatientProfileId, Timestamp = dataAudit.Timestamp.Value }; context.DataAuditHistories.Add(newDataAudit); await context.SaveChangesAsync(); return(newDataAudit.DataAuditHistoryId); }
public async Task <IActionResult> PostAsync(DataAuditRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } else if (request.OldValue == request.NewValue) { return(BadRequest("There is no change in the data. This request cannot be recorded as audit.")); } else if ((await changeAuditService.GetDeviceTypeId(request.DeviceTypeCode)) == 0) { return(BadRequest("Invalid Device Type Code.")); } else { await changeAuditService.InsertDataAuditAsync(request); } return(Accepted()); }