public async Task <IActionResult> UpdateStudentRecord([FromBody] StudentRecordUpdateRequest request) { var studentRecordUpdate = new StudentRecordUpdate { State = Enum.Parse <StudentRecordState>(request.State), StudentId = request.StudentId }; string serializedObj = JsonSerializer.Serialize(studentRecordUpdate); await _producer.ProduceAsync("Student", new Message <Null, string> { Value = serializedObj, Timestamp = new Timestamp(DateTime.UtcNow) }); return(Ok()); }
public IActionResult Update(string scope, int id, [FromBody] StudentRecordUpdate update) { if (!ModelState.IsValid) { return(new BadRequestObjectResult(new ErrorsResponse(ModelState))); } if (!_records.IsLocked(scope)) { return(StatusCode(422)); } var record = new StudentRecord { Id = id, StudentFirstName = update.StudentFirstName, StudentMiddleInitial = update.StudentMiddleInitial, StudentLastName = update.StudentLastName, StudentGradeLevel = update.StudentGradeLevel, StudentDateOfBirth = update.StudentDateOfBirth, StudentStreet1 = update.StudentStreet1, StudentStreet2 = update.StudentStreet2, StudentCity = update.StudentCity, StudentState = update.StudentState, StudentZipCode = update.StudentZipCode, StudentEnrollmentDate = update.StudentEnrollmentDate, StudentWithdrawalDate = update.StudentWithdrawalDate, StudentIsSpecialEducation = update.StudentIsSpecialEducation, StudentCurrentIep = update.StudentCurrentIep, StudentFormerIep = update.StudentFormerIep, StudentNorep = update.StudentNorep, }; var current = _records.Get(record.Id); var delta = MergeProperties(current, record, new[] { nameof(StudentRecord.Id), nameof(StudentRecord.StudentId), nameof(StudentRecord.SchoolDistrictId), nameof(StudentRecord.SchoolDistrictName), nameof(StudentRecord.Header), nameof(StudentRecord.LastUpdated), nameof(StudentRecord.ActivitySchoolYear), nameof(StudentRecord.StudentPaSecuredId), }); var username = User.FindFirst(c => c.Type == JwtRegisteredClaimNames.Sub).Value; using (var tx = _context.Database.BeginTransaction()) { try { _records.Update(current); _audits.Create(new AuditHeader { Username = username, Activity = AuditActivity.EDIT_STUDENT_RECORD, Timestamp = DateTime.Now, Identifier = current.StudentId, Details = delta.Select(d => new AuditDetail { Field = d.Key, Previous = d.Value.Previous, Next = d.Value.Next, }).ToList(), }); _context.SaveChanges(); tx.Commit(); } catch (Exception) { tx.Rollback(); throw; } } return(Ok()); }