public static Task <IHttpResponse> CreateAsync(
            [Property(Name = Resources.ProcessStageType.IdPropertyName)] Guid processStageTypeId,
            [Property(Name = Resources.ProcessStageType.OwnerPropertyName)] Guid ownerId,
            [Property(Name = Resources.ProcessStageType.GroupPropertyName)] Guid processStageGroupId,
            [Property(Name = Resources.ProcessStageType.TitlePropertyName)] string title,
            [Property(Name = Resources.ProcessStageType.ResourceTypePropertyName)] Type resourceType,
            [Property(Name = Resources.ProcessStageType.ResourceKeysPropertyName)] string[] resourceKeys,
            [Property(Name = Resources.ProcessStageType.ResourceTypesPropertyName)] Type[] resourceTypes,
            EastFive.Api.Security security, IHttpRequest request, IProvideUrl url,
            CreatedResponse onCreated,
            CreatedBodyResponse <ProcessStageType> onCreatedAndModified,
            AlreadyExistsResponse onAlreadyExists,
            AlreadyExistsReferencedResponse onRelationshipAlreadyExists,
            ReferencedDocumentNotFoundResponse onReferenceNotFound,
            UnauthorizedResponse onUnauthorized,
            GeneralConflictResponse onFailure)
        {
            var resourceList = resourceKeys.Zip(resourceTypes, (k, v) => k.PairWithValue(v)).ToArray();

            return(ProcessStageTypes.CreateAsync(processStageTypeId, ownerId, processStageGroupId, title,
                                                 resourceType, resourceList,
                                                 security,
                                                 () => onCreated(),
                                                 () => onAlreadyExists(),
                                                 () => onReferenceNotFound(),
                                                 (brokenId) => onReferenceNotFound(),
                                                 (why) => onFailure(why)));
        }
        public static Task <HttpResponseMessage> CreateConnectorAsync(
            [Property] Guid id,
            [Property(Name = EastFive.Api.Resources.Connector.SourcePropertyName)] Guid source,
            [Property(Name = EastFive.Api.Resources.Connector.DestinationPropertyName)] Guid destination,
            [Property(Name = EastFive.Api.Resources.Connector.FlowPropertyName)] Connector.SynchronizationMethod Flow,
            Security security, Context context, HttpRequestMessage request, UrlHelper url,
            CreatedResponse onCreated,
            CreatedBodyResponse <Resources.Connection> onCreatedAndModifiedConnection,
            CreatedBodyResponse <Resources.Connector> onCreatedAndModified,
            AlreadyExistsResponse onAlreadyExists,
            AlreadyExistsReferencedResponse onRelationshipAlreadyExists,
            ReferencedDocumentNotFoundResponse onReferenceNotFound,
            UnauthorizedResponse onUnauthorized,
            GeneralConflictResponse onFailure)
        {
            return(Connectors.CreateConnectorAsync(id, source, destination,
                                                   Flow, security.performingAsActorId, security.claims,
                                                   () => onCreated(),
                                                   (connection) =>
            {
                return request.Headers.Accept
                .OrderByDescending(accept => accept.Quality.HasValue ? accept.Quality.Value : 1.0)
                .First(
                    (accept, next) =>
                {
                    if (
                        accept.MediaType.ToLower() == "x-ordering/connection" ||
                        accept.MediaType.ToLower() == "x-ordering/connection+json")
                    {
                        return onCreatedAndModifiedConnection(
                            ConnectionController.GetResource(connection, url),
                            "x-ordering/connection+json");
                    }

                    if (
                        accept.MediaType.ToLower() == "x-ordering/connector" ||
                        accept.MediaType.ToLower() == "x-ordering/connector+json" ||
                        accept.MediaType.ToLower() == "application/json")
                    {
                        return onCreatedAndModified(
                            GetResource(connection.connector, url),
                            "x-ordering/connector+json");
                    }

                    return next();
                },
                    () => onCreatedAndModified(GetResource(connection.connector, url)));
            },
                                                   () => onAlreadyExists(),
                                                   (existingConnectorId) => onRelationshipAlreadyExists(existingConnectorId),
                                                   (brokenId) => onReferenceNotFound(),
                                                   (why) => onFailure(why)));
        }
Exemple #3
0
        public override Task <IHttpResponse> InstigateInternal(IApplication httpApp,
                                                               IHttpRequest request, ParameterInfo parameterInfo,
                                                               Func <object, Task <IHttpResponse> > onSuccess)
        {
            AlreadyExistsReferencedResponse dele =
                (existingId) =>
            {
                var response = request
                               .CreateResponse(StatusCode)
                               .AddReason($"There is already a resource with ID = [{existingId}]");
                return(UpdateResponse(parameterInfo, httpApp, request, response));
            };

            return(onSuccess((object)dele));
        }