public async Task Consume(ConsumeContext <StudentValue> context) { var auditData = new Audit_Data { Message = context.Message.Value }; await _auditRepository.Create(auditData); }
public ResponseMessage Create(LoggedDeviceEntity model, string identity) { ResponseMessage response = new ResponseMessage(); try { model.ProfileID = identity; response.IsSuccess = _loginDeviceHistoryRepository.Create(model).Result; } catch (Exception ex) { response.IsSuccess = false; response.ErrorMessage = ex.Message; } return(response); }
public override void HandleBasicDeliver(string consumerTag, ulong deliveryTag, bool redelivered, string exchange, string routingKey, IBasicProperties properties, ReadOnlyMemory <byte> readOnlyMemory) { var body = readOnlyMemory.Span; var message = Encoding.UTF8.GetString(body); var modelToAddInDb = new Audit_Data { Message = message, ConsumeDateTime = DateTime.UtcNow, ConsumerTag = consumerTag, DeliveryTag = deliveryTag.ToString(), ExchangeName = exchange, RoutingTag = routingKey }; _auditRepository.Create(modelToAddInDb); _model.BasicAck(deliveryTag, false); }
public async Task <IActionResult> Add([FromBody] AuditCreationDto auditDto) { if (!ModelState.IsValid) { return(BadRequest(new { message = ModelState.Values.SelectMany(v => v.Errors).Select(e => e.ErrorMessage) })); } var createAudit = _mapper.Map <Audit>(auditDto); try { createAudit.Timestamp = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); await _auditRepository.Create(createAudit); return(NoContent()); } catch (Exception e) { return(BadRequest(new MessageObj(e.Message))); } }
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()); }
public IActionResult Upload(string year, IFormFile file) { if (file == null) { return(new BadRequestObjectResult( new ErrorResponse($"Could not find parameter named '{nameof(file)}'."))); } if (!_parsers.ContainsKey(file.ContentType)) { return(new BadRequestObjectResult( new ErrorResponse($"Invalid file Content-Type '{file.ContentType}'."))); } var input = _parsers[file.ContentType](year, file.OpenReadStream()); var username = User.FindFirst(c => c.Type == JwtRegisteredClaimNames.Sub).Value; Calendar calendar; using (var tx = _context.Database.BeginTransaction()) { try { calendar = _calendars.Get(input.SchoolYear); if (calendar == null) { calendar = input; calendar.Created = DateTime.Now; calendar.LastUpdated = calendar.Created; _context.Add(calendar); } else { var details = new List <AuditDetail>(); var added = input.Days.Where(id => !calendar.Days.Any(cd => cd.Date == id.Date)); Console.WriteLine("Added:"); foreach (var add in added) { Console.WriteLine($"\t{add.Date}"); } foreach (var add in added) { details.Add(new AuditDetail { Field = "Day", Next = add.Date.ToString("MM/dd/yyyy"), }); } var removed = calendar.Days.Where(cd => !input.Days.Any(id => id.Date == cd.Date)); Console.WriteLine("Removed:"); foreach (var remove in removed) { Console.WriteLine($"\t{remove.Date}"); } foreach (var remove in removed) { details.Add(new AuditDetail { Field = "Day", Previous = remove.Date.ToString("MM/dd/yyyy"), }); } _context.Remove(calendar); input.Created = calendar.Created; input.LastUpdated = DateTime.Now; _context.Add(input); calendar = input; _audits.Create(new AuditHeader { Username = username, Activity = AuditActivity.UPDATE_SCHOOL_CALENDAR, Timestamp = DateTime.Now, Identifier = calendar.SchoolYear, Details = details, }); } _context.SaveChanges(); tx.Commit(); } catch (Exception) { tx.Rollback(); throw; } } return(new CreatedResult($"/api/calendars/{year}", new CalendarResponse { Calendar = calendar, })); }
public async Task <IActionResult> Upload(string type, string year, IFormFile content) { if (!ReportType.Values().Contains(type)) { return(new BadRequestObjectResult(new ErrorResponse($"Invalid ReportType '{type}'."))); } if (!new Regex(@"^\d{4}-\d{4}$").IsMatch(year)) { return(new BadRequestObjectResult(new ErrorResponse($"Invalid SchoolYear '{year}'"))); } if (content == null) { return(new BadRequestObjectResult( new ErrorResponse($"Could not find parameter named '{nameof(content)}'."))); } if (content.ContentType != ContentTypes.XLSX) { return(new BadRequestObjectResult( new ErrorResponse($"Invalid file Content-Type '{content.ContentType}'."))); } Template template; using (var ms = new MemoryStream()) { content.OpenReadStream().CopyTo(ms); template = new Template { ReportType = ReportType.FromString(type), SchoolYear = year, Name = content.FileName, Content = ms.ToArray(), }; } template = await Task.Run(() => _context.SaveChanges(() => _templates.CreateOrUpdate(template))); var username = User.FindFirst(c => c.Type == JwtRegisteredClaimNames.Sub).Value; using (var tx = _context.Database.BeginTransaction()) { try { _context.SaveChanges(() => _audits.Create(new AuditHeader { Username = username, Activity = AuditActivity.UPDATE_TEMPLATE, Timestamp = DateTime.Now, Identifier = $"{template.ReportType}_{template.SchoolYear}", })); tx.Commit(); } catch (Exception) { tx.Rollback(); throw; } } return(new CreatedResult($"/api/templates/{template.ReportType}/{template.SchoolYear}", new TemplateResponse { Template = new TemplateDto(template), })); }
private async Task RecordDeviceLoggedInFrom(LoggedDeviceEntity userAgent, User user) { userAgent.ProfileID = user.PublicID; await _auditRepository.Create(userAgent); }