public async Task <IActionResult> CreateGroup([FromBody] CreateAssetCommand command) { command.IsGroup = true; var newValue = await _assetService.Create(command); foreach (var item in command.Assets) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.AssetGroup, FromId = newValue.Id, ToType = ObjectType.Asset, ToId = item }); } if (command.ContainerRootId.HasValue) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Container, FromId = command.ContainerRootId.Value, ToType = ObjectType.AssetGroup, ToId = newValue.Id }); } _auditTrailService.LogAction(AuditTrailAction.CreateAssetGroup, newValue.Id, new AuditTrailPayloadModel() { Data = JsonConvert.SerializeObject(command) }); return(Ok(newValue)); }
public Asset Create(CreateAssetCommand command) { var newValue = _assetService.Create(command).Result; if (command.ContainerRootId.HasValue) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Container, FromId = command.ContainerRootId.Value, ToType = ObjectType.Asset, ToId = newValue.Id, CreateByUserId = command.CreateByUserId, Payload = JsonConvert.SerializeObject(new AssetPayloadModel() { X = command.PayloadData?.X, Y = command.PayloadData?.Y }) }); } _auditTrailService.LogAction(AuditTrailAction.CreateAsset, newValue.Id, new AuditTrailPayloadModel() { Data = JsonConvert.SerializeObject(command) }); return(newValue); }
public async Task <IActionResult> CreateTreatment([FromBody] CreateTreatmentCommand command) { var newValue = await _treatmentService.Create(command); _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Asset, FromId = command.AssetId, ToType = ObjectType.Treatment, ToId = newValue.Id }); _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Risk, FromId = command.RiskId, ToType = ObjectType.Treatment, ToId = newValue.Id }); _auditTrailService.LogAction(AuditTrailAction.CreateTreatment, newValue.Id, new AuditTrailPayloadModel() { Data = JsonConvert.SerializeObject(command) }); return(Created(newValue.Id.ToString(), newValue)); }
public Vulnerability CreateVulnerability(CreateVulnerabilityCommand command) { var newValue = _vulnerabilityService.Create(command).Result; _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Asset, FromId = command.AssetId, ToType = ObjectType.Vulnerabilitie, ToId = newValue.Id, CreateByUserId = command.CreateByUserId }); _auditTrailService.LogAction(AuditTrailAction.CreateVulnerabilities, newValue.Id, new AuditTrailPayloadModel() { Data = JsonConvert.SerializeObject(command) }); return(newValue); }
public async Task <IActionResult> CreateEdge([FromBody] CreateEdgeCommand command) { var newValue = await _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Asset, FromId = command.Asset1Guid, ToType = ObjectType.Asset, ToId = command.Asset2Guid, Payload = JsonConvert.SerializeObject(new AssetEdgePayloadModel() { Name = command.Name, Asset1Anchor = command.Asset1Anchor, Asset2Anchor = command.Asset2Anchor }) }); if (command.ContainerRootId.HasValue) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Container, FromId = command.ContainerRootId.Value, ToType = ObjectType.AssetEdge, ToId = newValue.Id }); } return(Ok(newValue)); }
public Relationship CreateEdge(CreateEdgeCommand command) { var newValue = _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Asset, FromId = command.Asset1Guid, ToType = ObjectType.Asset, ToId = command.Asset2Guid, CreateByUserId = command.CreateByUserId, Payload = JsonConvert.SerializeObject(new AssetEdgePayloadModel() { Name = command.Name, Asset1Anchor = command.Asset1Anchor, Asset2Anchor = command.Asset2Anchor }) }); if (command.ContainerRootId.HasValue) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Container, FromId = command.ContainerRootId.Value, ToType = ObjectType.AssetEdge, ToId = newValue.Id, CreateByUserId = command.CreateByUserId }); } return(newValue); }
public Risk CreateRisk(CreateRiskCommand command) { var newValue = _riskService.Create(command).Result; _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Asset, FromId = command.AssetId, ToType = ObjectType.Risk, ToId = newValue.Id }); foreach (var item in command.Vulnerabilities) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Risk, FromId = newValue.Id, ToType = ObjectType.Vulnerabilitie, ToId = item }); } foreach (var item in command.Risks) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Risk, FromId = newValue.Id, ToType = ObjectType.Risk, ToId = item }); } foreach (var item in command.Treatments) { var treatment = _treatmentService.Create(new CreateTreatmentCommand() { RiskId = newValue.Id, Name = item.Name, Description = item.Description, Type = item.Type }).Result; _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Asset, ToType = ObjectType.TreatmentPayload, FromId = command.AssetId, ToId = treatment.Payload.Id }); } _auditTrailService.LogAction(AuditTrailAction.CreateRisk, newValue.Id, new AuditTrailPayloadModel() { Data = JsonConvert.SerializeObject(command) }); return(newValue); }
public async Task <IActionResult> Create([FromBody] CreateDeleteRelationshipRequest request) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var newlyAddedRelationship = await _relationshipService.Create(request); return(new ObjectResult(newlyAddedRelationship)); } catch (InvalidOperationException e) { return(NotFound(new { message = e.Message })); } }
public async Task <IActionResult> Create([FromBody] CreateContainerCommand command) { var newValue = await _containerService.Create(command); _auditTrailService.LogAction(AuditTrailAction.CreateContainer, newValue.Id, new AuditTrailPayloadModel() { Data = JsonConvert.SerializeObject(command) }); if (command.ParentRootId.HasValue) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Container, ToType = ObjectType.Container, FromId = command.ParentRootId.Value, ToId = newValue.RootId, Branch = command.Branch }); } return(Ok(newValue)); }
public Container Create(CreateContainerCommand command) { var newValue = _containerService.Create(command).Result; _auditTrailService.LogAction(AuditTrailAction.CreateContainer, newValue.Id, new AuditTrailPayloadModel() { Data = JsonConvert.SerializeObject(command) }); if (command.ParentRootId.HasValue) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Container, ToType = ObjectType.Container, FromId = command.ParentRootId.Value, ToId = newValue.RootId, Branch = command.Branch, CreateByUserId = command.CreateByUserId }); } return(newValue); }
public Treatment CreateTreatment(CreateTreatmentCommand command) { var newValue = _treatmentService.Create(command).Result; _relationshipService.Create(new CreateRelationshipCommand() { FromType = _assetService.GetSingle(x => x.Id == command.AssetId) != null ? ObjectType.Asset : ObjectType.AssetEdge, FromId = command.AssetId, ToType = ObjectType.TreatmentPayload, ToId = newValue.Payload.Id, CreateByUserId = command.CreateByUserId }); _auditTrailService.LogAction(AuditTrailAction.CreateTreatment, newValue.Id, new AuditTrailPayloadModel() { Data = JsonConvert.SerializeObject(command) }); return(newValue); }
public async Task <IActionResult> CreateRisk([FromBody] CreateRiskCommand command) { var newValue = await _riskService.Create(command); _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Asset, FromId = command.AssetId, ToType = ObjectType.Risk, ToId = newValue.Id }); foreach (var item in command.Vulnerabilities) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Risk, FromId = newValue.Id, ToType = ObjectType.Vulnerabilitie, ToId = item }); } foreach (var item in command.Risks) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Risk, FromId = newValue.Id, ToType = ObjectType.Risk, ToId = item }); } foreach (var item in command.Treatments) { _relationshipService.Create(new CreateRelationshipCommand() { FromType = ObjectType.Risk, FromId = newValue.Id, ToType = ObjectType.Treatment, ToId = item.Id }); } _auditTrailService.LogAction(AuditTrailAction.CreateRisk, newValue.Id, new AuditTrailPayloadModel() { Data = JsonConvert.SerializeObject(command) }); return(Created(newValue.Id.ToString(), newValue)); }