public async Task <int> Create(NormalizedLog model) { var dto = model.ToDomainModel(); dto.CustomAttributeValues = new List <CustomAttributeValue>(); var entity = await _db.NormalizedLog.AddAsync(dto); await _db.SaveChangesAsync(); entity.State = EntityState.Detached; var valueDtos = new List <CustomAttributeValue>(); foreach (var customAttributeValue in model.CustomAttributeValues) { var valueDto = customAttributeValue.ToDomainModel(); valueDto.NormalizedLogId = entity.Entity.NormalizedLogId; valueDtos.Add(valueDto); } await _db.CustomAttributeValue.AddRangeAsync(valueDtos); await _db.SaveChangesAsync(); return(entity.Entity.NormalizedLogId); }
public async Task <int> Create(SeverityRule model) { var severityRuleDto = model.ToDomainModel(); var generalRuleId = severityRuleDto.GeneralRuleId; if (!DoesGeneralRuleExists(generalRuleId)) { if (model.GeneralRule == null) { throw new ArgumentException(); } generalRuleId = await _generalRuleRepository.Create(model.GeneralRule); } severityRuleDto.GeneralRuleId = generalRuleId; var entity = await _db.SeverityLevelRule.AddAsync(severityRuleDto); await _db.SaveChangesAsync(); entity.State = EntityState.Detached; return(entity.Entity.SeverityLevelRuleId); }
public async Task <int> Create(Processor.Model.System model) { var dto = model.ToDomainModel(); dto.Component = null; var entity = _db.System.Add(dto); await _db.SaveChangesAsync(); foreach (var modelComponent in model.Components) { var dtoComponent = modelComponent.ToDomainModel(); var exists = await _db.Component.AnyAsync(); dtoComponent.SystemId = entity.Entity.SystemId; if (exists) { _db.Component.Update(dtoComponent); } else { await _db.Component.AddAsync(dtoComponent); } await _db.SaveChangesAsync(); } entity.State = EntityState.Detached; return(entity.Entity.SystemId); }
public async Task <int> Create(RawLog model) { var dto = model.ToDomainModel(); var entity = _db.RawLog.Add(dto); await _db.SaveChangesAsync(); return(entity.Entity.RawLogId); }
public async Task <int> Create(Alert model) { var dto = model.ToDomainModel(); _db.Alert.Add(dto); await _db.SaveChangesAsync(); return(dto.AlertId); }
public async Task <int> Create(Component model) { var dto = model.ToDomainModel(); _db.Component.Add(dto); await _db.SaveChangesAsync(); return(dto.ComponentId); }
public async Task <int> Create(GeneralRule model) { var dto = model.ToDomainModel(); var entity = _db.GeneralRule.Add(dto); await _db.SaveChangesAsync(); entity.State = EntityState.Detached; return(entity.Entity.GeneralRuleId); }
public async Task <int> Create(DateTimeRule model) { var generalRuleId = await _generalRuleRepository.Create(model.GeneralRule); model.GeneralRuleId = generalRuleId; var entity = await _db.DateTimeRule.AddAsync(model.ToDomainModel()); await _db.SaveChangesAsync(); return(entity.Entity.DateTimeRuleId); }
public async Task UpdateAnalyzerFrequencySettings(Settings model) { var dto = model.ToDomainModel(); _db.Settings.Update(dto); await _db.SaveChangesAsync(); }
public async Task <int> Create(AlertGroup model) { var dto = model.ToDomainModel(); var alerts = dto.AlertGroupAlert; dto.AlertGroupAlert = null; var alertGroupEntity = _db.AlertGroup.Add(dto); await _db.SaveChangesAsync(); var createdId = alertGroupEntity.Entity.AlertGroupId; _db.AddRange(alerts.Select(e => { e.AlertGroupId = createdId; return(e); })); await _db.SaveChangesAsync(); return(createdId); }
public async Task <int> Create(ParsingRules model) { var dto = model.ToDomainModel(); var component = dto.Components.First(); dto.Components = null; var entity = _db.ParsingRules.Add(dto); await _db.SaveChangesAsync(); entity.State = EntityState.Detached; component.ParsingRulesId = entity.Entity.ParsingRulesId; var componentEntity = _db.Component.Update(component); await _db.SaveChangesAsync(); componentEntity.State = EntityState.Detached; return(entity.Entity.ParsingRulesId); }
public async Task <SystemReport> GenerateReportForSystem(int systemId) { var timestamp = DateTime.Now; var systemAlertGroups = await _db.AlertGroup.Where(ag => ag.SystemId == systemId).ToListAsync(); var reportAlertGroups = new List <SystemReportAlertGroup>(); var report = new Models.SystemReport { SystemReportId = 0, SystemId = systemId, Timestamp = timestamp }; var systemReportEntity = _db.SystemReport.Add(report); await _db.SaveChangesAsync(); var createdSystemReportId = systemReportEntity.Entity.SystemReportId; systemReportEntity.State = EntityState.Detached; foreach (var systemAlertGroup in systemAlertGroups) { var counted = await _db.AlertGroupValue.CountAsync(agv => agv.AlertGroupId == systemAlertGroup.AlertGroupId); var temp = new SystemReportAlertGroup { SystemReportAlertGroupId = 0, SystemReportId = createdSystemReportId, AlertGroupId = systemAlertGroup.AlertGroupId, Count = counted }; reportAlertGroups.Add(temp); } _db.SystemReportAlertGroup.AddRange(reportAlertGroups); await _db.SaveChangesAsync(); var components = await _db.Component.Where(c => c.SystemId != null && c.SystemId == systemId).ToListAsync(); foreach (var component in components) { var componentReportAlerts = new List <ComponentReportAlert>(); var componentReport = new ComponentReport { ComponentReportId = 0, SystemReportId = createdSystemReportId, ComponentId = component.ComponentId, Timestamp = timestamp }; var componentReportEntity = _db.ComponentReport.Add(componentReport); await _db.SaveChangesAsync(); var createdComponentReportId = componentReportEntity.Entity.ComponentReportId; componentReportEntity.State = EntityState.Detached; var componentAlerts = await _db.Alert.Where(a => a.ComponentId == component.ComponentId).ToListAsync(); foreach (var componentAlert in componentAlerts) { var alertCount = await _db.AlertValue.CountAsync(av => av.AlertId == componentAlert.AlertId); var temp = new ComponentReportAlert { ComponentReportAlertId = 0, AlertId = componentAlert.AlertId, Count = alertCount, ComponentReportId = createdComponentReportId }; componentReportAlerts.Add(temp); } _db.ComponentReportAlert.AddRange(componentReportAlerts); await _db.SaveChangesAsync(); } return(await GetReport(createdSystemReportId)); }