コード例 #1
0
        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")
            });
コード例 #2
0
ファイル: ReferenceService.cs プロジェクト: Strongminds/kitos
        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)
                   ));
        }
コード例 #3
0
 public Maybe <IEntityWithExternalReferences> GetRootEntity(int id, ReferenceRootType rootType)
 {
     return(ResolveRepositoryOperations(rootType).Get(id));
 }
コード例 #4
0
 private void ExpectGetRootEntityReturns(int id, ReferenceRootType rootType, Maybe <IEntityWithExternalReferences> value)
 {
     _referenceRepository.Setup(x => x.GetRootEntity(id, rootType)).Returns(value);
 }
コード例 #5
0
 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());
 }