private IActionResult AddObjectDefinition(ServiceModels.ObjectDefinition objectDefinition)
        {
            IActionResult result;

            if (objectDefinition == null)
            {
                result = new BadRequestResult();
            }
            else
            {
                ResourceCreated        response = new ResourceCreated();
                string                 rootUrl  = Request.GetRootUrl();
                Model.ObjectDefinition item     = objectDefinition.ToModel();
                item.OrganisationID = User.GetOrganisationID();
                try
                {
                    BusinessLogicFactory.ObjectDefinitions.SaveObjectDefinition(item, Model.TObjectState.Add);
                    response.ID = StringUtils.GuidEncode(item.ObjectDefinitionID);
                    response.AddSelfLink(string.Concat(rootUrl, "/objecttypes/definitions/", response.ID), false, false);
                    result = Request.GetObjectResult(response, System.Net.HttpStatusCode.Created);
                }
                catch (ConflictException)
                {
                    result = new StatusCodeResult((int)HttpStatusCode.Conflict);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create Object/Resource in Identity Manager Service  (async await)
        /// </summary>
        /// <param name="resource">Resource to be created</param>
        /// <returns>Resource with its newly assigned ObjectID</returns>
        public async Task <IdmResource> PostAsync(IdmResource resource)
        {
            if (resource == null)
            {
                throw new ArgumentNullException("resource");
            }

            var createRequestMessage = BuildCreateRequestMessage(resource);

            // Add the required header for the Create action
            createRequestMessage.Headers.Add(MessageHeader.CreateHeader("IdentityManagementOperation", SoapConstants.DirectoryAccess, null, true));


            Message addResponseMsg = await _factoryClient.CreateAsync(createRequestMessage);

            if (addResponseMsg.IsFault)
            {
                throw new SoapFaultException("Create Fault: " + addResponseMsg);
            }

            // Deserialize the Add response
            ResourceCreated resourceCreatedObject = addResponseMsg.GetBody <ResourceCreated>(new SoapXmlSerializer(typeof(ResourceCreated)));

            resource.ObjectID = resourceCreatedObject.EndpointReference.ReferenceProperties.ResourceReferenceProperty.Value.Substring(9);;

            return(resource);
        }
Exemplo n.º 3
0
        public void Handle(ResourceCreated msg, IEventsDispatcher eventsDispatcher)
        {
            Debug.WriteLine($"PagespeedChecker: handling ResourceCreated({msg.ResourceId})");

            _repositoryFactory.Execute(repository =>
            {
                repository.Commit();
            });
        }
Exemplo n.º 4
0
        public void Can_roundtrip_ResourceCreated_instance()
        {
            // Arrange
            var resourceEvent = new ResourceCreated <MyResource>(
                "createdInTest",
                new MyResource("test-1234", "My named resource"));

            // Act
            var asJson     = JsonSerializer.Serialize(resourceEvent, JsonSerializerOptions);
            var rehydrated = JsonSerializer.Deserialize <ResourceCreated <MyResource> >(asJson, JsonSerializerOptions);

            // Assert
            rehydrated.Should().BeEquivalentTo(resourceEvent);
        }
Exemplo n.º 5
0
        public async virtual Task <IActionResult> CreateAsync(ResourceModel <TResource> resourceModel)
        {
            if (!User.IsAuthorized(ResourceType))
            {
                return(Unauthorized());
            }

            var createResourceEvent = new CreateResource <TResource>(resourceModel);
            var context             = await _mediator.Send(createResourceEvent);

            if (context != null)
            {
                resourceModel = context;
            }

            if (resourceModel.Errors.Any())
            {
                foreach (var error in resourceModel.Errors)
                {
                    ModelState.AddModelError(error.Key, error.Value);
                }
            }

            if (!ModelState.IsValid)
            {
                return(PartialView("_Editor", resourceModel));
            }

            int newResourceID = await _repository.CreateAsync(resourceModel.Resource, UserID);

            if (newResourceID == 0)
            {
                return(NoContent());
            }

            _logger.LogResourceCreated(ResourceType, resourceModel.ID);

            var resourceCreatedEvent = new ResourceCreated <TResource>(resourceModel.Resource);
            await _mediator.Publish(resourceCreatedEvent);

            var resourcePersistedEvent = new ResourcePersisted <TResource>();
            await _mediator.Publish(resourcePersistedEvent);

            var controllerName = ControllerContext.RouteData.Values["controller"].ToString();

            return(Created(Url.Action("ReadAsync", controllerName, new { id = newResourceID }), newResourceID));
        }
        public async Task InvokeAsync(
            HttpContext context,
            IContentStorage contentStore,
            JsonService jsonService)
        {
            RestContentItem input = await jsonService.Deserialize <RestContentItem>(context.Request.Body);

            ContentItem model = input.ToModel();

            await contentStore.UpdateAsync(model);

            ResourceCreated result = new ResourceCreated()
            {
                Id = input.Id
            };

            string json = jsonService.Serialize(result);

            await context.Response.WriteAsync(json);
        }
Exemplo n.º 7
0
        public async Task InvokeAsync(
            HttpContext context,
            IAssetStorage assetStore,
            JsonService jsonService)
        {
            RestAsset restAsset = await jsonService.Deserialize <RestAsset>(context.Request.Body);

            Asset asset = restAsset.ToModel();

            await assetStore.CreateAsync(asset);

            var r = new ResourceCreated()
            {
                Id = asset.Id
            };

            string json = jsonService.Serialize(r);

            await context.Response.WriteAsync(json);
        }
Exemplo n.º 8
0
        public async Task InvokeAsync(
            HttpContext context,
            ISchemaStorage schemaStorage,
            JsonService jsonService)
        {
            string name = (string)context.GetRouteValue("name");

            RestContentSchema input = await jsonService.Deserialize <RestContentSchema>(context.Request.Body);

            ContentSchema m = input.ToModel();

            await schemaStorage.CreateAsync(m);

            var result = new ResourceCreated()
            {
                Id = m.Id
            };

            string json = jsonService.Serialize(result);

            await context.Response.WriteAsync(json);
        }
Exemplo n.º 9
0
 public void Apply(ResourceCreated evt)
 {
     this.Id = evt.Id;
     this.Description = evt.Description;
 }
Exemplo n.º 10
0
 public void Apply(ResourceCreated evt)
 {
     this.Id          = evt.Id;
     this.Description = evt.Description;
 }
Exemplo n.º 11
0
        public void It_has_a_ResourceCreated_model_with_a_default_ctor_that_does_nothing()
        {
            var it = new ResourceCreated();

            Assert.IsNull(it.EndpointReference);
        }