public Result <ItSystem, OperationError> GetSystem(Guid uuid) { return(_itSystemRepository .GetSystem(uuid) .Match ( system => _authorizationContext.AllowReads(system) ? Result <ItSystem, OperationError> .Success(system) : new OperationError(OperationFailure.Forbidden), () => new OperationError(OperationFailure.NotFound) )); }
public Result <ItInterface, OperationFailure> ChangeExposingSystem(int interfaceId, int?newSystemId) { using (var transaction = _transactionManager.Begin(IsolationLevel.ReadCommitted)) { var itInterface = _repository.GetByKey(interfaceId); if (itInterface == null) { return(OperationFailure.NotFound); } if (!_authorizationContext.AllowModify(itInterface)) { return(OperationFailure.Forbidden); } Maybe <ItInterfaceExhibit> oldExhibit = itInterface.ExhibitedBy; Maybe <ItSystem> oldSystem = itInterface.ExhibitedBy?.ItSystem; var newSystem = Maybe <ItSystem> .None; if (newSystemId.HasValue) { newSystem = _systemRepository.GetSystem(newSystemId.Value).FromNullable(); if (newSystem.IsNone) { return(OperationFailure.BadInput); } if (!_authorizationContext.AllowReads(newSystem.Value)) { return(OperationFailure.Forbidden); } } var newExhibit = itInterface.ChangeExhibitingSystem(newSystem); var changed = !oldExhibit.Equals(newExhibit); if (changed) { _domainEvents.Raise(new ExposingSystemChanged(itInterface, oldSystem, newExhibit.Select(x => x.ItSystem))); if (oldSystem.HasValue) { _domainEvents.Raise(new EntityUpdatedEvent <ItSystem>(oldSystem.Value)); } if (newSystem.HasValue) { _domainEvents.Raise(new EntityUpdatedEvent <ItSystem>(newSystem.Value)); } _repository.Save(); transaction.Commit(); } return(itInterface); } }
public Result <ItSystemUsageMigration, OperationFailure> GetSystemUsageMigration(int usageId, int toSystemId) { if (!CanExecuteMigration()) { return(OperationFailure.Forbidden); } // Get usage var itSystemUsage = _systemUsageRepository.GetSystemUsage(usageId); if (itSystemUsage == null) { return(OperationFailure.BadInput); } if (!_authorizationContext.AllowReads(itSystemUsage)) { return(OperationFailure.Forbidden); } // Get system var toItSystem = _systemRepository.GetSystem(toSystemId); if (toItSystem == null) { return(OperationFailure.BadInput); } if (!_authorizationContext.AllowReads(toItSystem)) { return(OperationFailure.Forbidden); } if (toItSystem.Disabled) { return(OperationFailure.BadInput); } // Get contracts var contracts = itSystemUsage.Contracts.Select(x => x.ItContract); // Map relations var relationMigrations = GetRelationMigrations(itSystemUsage); return(new ItSystemUsageMigration( systemUsage: itSystemUsage, fromItSystem: itSystemUsage.ItSystem, toItSystem: toItSystem, affectedProjects: itSystemUsage.ItProjects, affectedContracts: contracts, affectedRelations: relationMigrations)); }
public Result <ItSystemUsage, OperationFailure> Add(ItSystemUsage newSystemUsage) { // create the system usage var existing = GetByOrganizationAndSystemId(newSystemUsage.OrganizationId, newSystemUsage.ItSystemId); if (existing != null) { return(OperationFailure.Conflict); } if (!_authorizationContext.AllowCreate <ItSystemUsage>(newSystemUsage.OrganizationId, newSystemUsage)) { return(OperationFailure.Forbidden); } var itSystem = _systemRepository.GetSystem(newSystemUsage.ItSystemId); if (itSystem == null) { return(OperationFailure.BadInput); } if (!_authorizationContext.AllowReads(itSystem)) { return(OperationFailure.Forbidden); } //Cannot create system usage in an org where the logical it system is unavailable to the users. if (!AllowUsageInTargetOrganization(newSystemUsage, itSystem)) { return(OperationFailure.Forbidden); } var usage = _usageRepository.Create(); usage.ItSystemId = newSystemUsage.ItSystemId; usage.OrganizationId = newSystemUsage.OrganizationId; _usageRepository.Insert(usage); _usageRepository.Save(); // abuse this as UoW _domainEvents.Raise(new EntityCreatedEvent <ItSystemUsage>(usage)); return(usage); }
protected override IControllerCrudAuthorization GetCrudAuthorization() { return(new ChildEntityCrudAuthorization <AccessType, ItSystem>(accessType => _systemRepository.GetSystem(accessType.ItSystemId), base.GetCrudAuthorization())); }
public Result <IEnumerable <ExternalReference>, OperationFailure> DeleteBySystemId(int systemId) { var system = _itSystemRepository.GetSystem(systemId); return(DeleteExternalReferences(system)); }