public IQueryable <ExternalReference> GetByRootType(ReferenceRootType rootType) { var baseQuery = _referenceRepository.AsQueryable(); return(rootType switch { ReferenceRootType.System => baseQuery.Where(x => x.ItSystem_Id != null), ReferenceRootType.SystemUsage => baseQuery.Where(x => x.ItSystemUsage_Id != null), ReferenceRootType.Contract => baseQuery.Where(x => x.Itcontract_Id != null), ReferenceRootType.Project => baseQuery.Where(x => x.ItProject_Id != null), ReferenceRootType.DataProcessingRegistration => baseQuery.Where(x => x.DataProcessingRegistration_Id != null), _ => throw new ArgumentOutOfRangeException(nameof(rootType), rootType, "Unknown reference root type") });
public Result <ExternalReference, OperationError> AddReference( int rootId, ReferenceRootType rootType, string title, string externalReferenceId, string url, Display display) { return(_referenceRepository .GetRootEntity(rootId, rootType) .Match ( onValue: root => { if (!_authorizationContext.AllowModify(root)) { return new OperationError("Not allowed to modify root entity", OperationFailure.Forbidden); } return root .AddExternalReference(new ExternalReference { Title = title, ExternalReferenceId = externalReferenceId, URL = url, Display = display, Created = _operationClock.Now, }) .Match <Result <ExternalReference, OperationError> > ( onSuccess: createdReference => { _referenceRepository.SaveRootEntity(root); _domainEvents.Raise(new EntityCreatedEvent <ExternalReference>(createdReference)); return createdReference; }, onFailure: error => error ); }, onNone: () => new OperationError("Root entity could not be found", OperationFailure.NotFound) )); }
public Maybe <IEntityWithExternalReferences> GetRootEntity(int id, ReferenceRootType rootType) { return(ResolveRepositoryOperations(rootType).Get(id)); }
private void ExpectGetRootEntityReturns(int id, ReferenceRootType rootType, Maybe <IEntityWithExternalReferences> value) { _referenceRepository.Setup(x => x.GetRootEntity(id, rootType)).Returns(value); }
private static Maybe <KeyValuePair <ReferenceRootType, int> > GetOwnerTypeAndIdOrFallback(ReferenceRootType ownerType, int?ownerId, Func <Maybe <KeyValuePair <ReferenceRootType, int> > > fallback) { return(ownerId.HasValue ? new KeyValuePair <ReferenceRootType, int>(ownerType, ownerId.Value) : fallback()); }