예제 #1
0
        private static async Task <string> CreateOrganizationAsync(string organization)
        {
            try
            {
                var request = new CreateOrganizationRequest()
                {
                    DisplayName = organization
                };


                HttpResponseMessage response = await client.PostAsync("Organization", new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"));

                response.EnsureSuccessStatusCode();
                var responseObj = await response.Content.ReadAsAsync <CreateOrganizationResponse>();

                return(responseObj.OrganizationId);
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine("\nException Caught!");
                Console.WriteLine("Message :{0} ", e.Message);
            }

            return(string.Empty);
        }
예제 #2
0
        public static void ClassInit(TestContext context)
        {
            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();
            credentials.User = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }
            CreateOrganizationRequest org = new CreateOrganizationRequest();
            org.Name = "test_" + Guid.NewGuid().ToString();
            var newOrg = client.Organizations.CreateOrganization(org).Result;
            orgGuid = newOrg.EntityMetadata.Guid;

            CreateSpaceRequest spc = new CreateSpaceRequest();
            spc.Name = "test_" + Guid.NewGuid().ToString();
            spc.OrganizationGuid = orgGuid;
            var newSpace = client.Spaces.CreateSpace(spc).Result;
            spaceGuid = newSpace.EntityMetadata.Guid;

            CreatesSharedDomainDeprecatedRequest r = new CreatesSharedDomainDeprecatedRequest();
            r.Name = Guid.NewGuid().ToString() + ".com";
            r.Wildcard = true;
            domainGuid = client.DomainsDeprecated.CreatesSharedDomainDeprecated(r).Result.EntityMetadata.Guid;
        }
예제 #3
0
        public static void ClassInit(TestContext context)
        {
            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();
            credentials.User = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }

            CreateOrganizationRequest org = new CreateOrganizationRequest();
            org.Name = "test_" + Guid.NewGuid().ToString();
            var newOrg = client.Organizations.CreateOrganization(org).Result;
            orgGuid = newOrg.EntityMetadata.Guid;

            CreateSpaceRequest spc = new CreateSpaceRequest();
            spc.Name = "test_" + Guid.NewGuid().ToString();
            spc.OrganizationGuid = orgGuid;
            var newSpace = client.Spaces.CreateSpace(spc).Result;
            spaceGuid = newSpace.EntityMetadata.Guid;

            stackGuid = client.Stacks.ListAllStacks().Result[0].EntityMetadata.Guid;
        }
        public static void ClassInit(TestContext context)
        {
            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();

            credentials.User     = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }

            CreateOrganizationRequest org = new CreateOrganizationRequest();

            org.Name = "test_" + Guid.NewGuid().ToString();
            var newOrg = client.Organizations.CreateOrganization(org).Result;

            orgGuid = newOrg.EntityMetadata.Guid;

            CreateSpaceRequest spc = new CreateSpaceRequest();

            spc.Name             = "test_" + Guid.NewGuid().ToString();
            spc.OrganizationGuid = orgGuid;
            var newSpace = client.Spaces.CreateSpace(spc).Result;

            spaceGuid = newSpace.EntityMetadata.Guid;

            stackGuid = client.Stacks.ListAllStacks().Result[0].EntityMetadata.Guid;
        }
예제 #5
0
        public async Task <IActionResult> CreateOrganization([FromBody] CreateOrganizationRequest request)
        {
            try
            {
                var response = await accountService.CreateOrganization(request);

                return(Ok(response));
            }
            catch (Exception ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
예제 #6
0
        public async Task <IActionResult> CreateAsync([FromBody] CreateOrganizationRequest request)
        {
            var org = new Organization()
            {
                Name = request.Name,
            };

            await OrganizationRepository.CreateAsync(org);

            var orgDto = Mapper.Map <OrganizationDto>(org);

            return(CreatedAtAction(nameof(GetById), new { id = orgDto.Id }, orgDto));
        }
        public void TestCreateOrganizationRequest()
        {
            string json = @"{
  ""name"": ""my-org-name"",
  ""quota_definition_guid"": ""1e863ed8-2c0b-44a2-bc27-9c670b6bbc39""
}";

            CreateOrganizationRequest request = new CreateOrganizationRequest();

            request.Name = "my-org-name";
            request.QuotaDefinitionGuid = new Guid("1e863ed8-2c0b-44a2-bc27-9c670b6bbc39");
            string result = JsonConvert.SerializeObject(request, Formatting.None);
            Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result);
        }
예제 #8
0
        /// <summary>
        /// CreateOrganization接口的同步版本,创建企业组织
        /// </summary>
        /// <param name="req">参考<see cref="CreateOrganizationRequest"/></param>
        /// <returns>参考<see cref="CreateOrganizationResponse"/>实例</returns>
        public CreateOrganizationResponse CreateOrganizationSync(CreateOrganizationRequest req)
        {
            JsonResponseModel <CreateOrganizationResponse> rsp = null;

            try
            {
                var strResp = this.InternalRequestSync(req, "CreateOrganization");
                rsp = JsonConvert.DeserializeObject <JsonResponseModel <CreateOrganizationResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
예제 #9
0
        public void TestCreateOrganizationRequest()
        {
            string json = @"{
  ""name"": ""my-org-name"",
  ""quota_definition_guid"": ""3743ed9f-e08a-4b7d-a6f4-72d7bd74688b""
}";

            CreateOrganizationRequest request = new CreateOrganizationRequest();

            request.Name = "my-org-name";
            request.QuotaDefinitionGuid = new Guid("3743ed9f-e08a-4b7d-a6f4-72d7bd74688b");
            string result = JsonConvert.SerializeObject(request, Formatting.None);

            Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result);
        }
 public async Task <IActionResult> Create([FromBody] CreateOrganizationRequest createReq)
 {
     using (_logger.BeginScope("----- Create -----"))
     {
         try
         {
             return(Ok(await _service.AddNewOrganization(new Organization(createReq.Name, createReq.OwnerSub, createReq.Address1, createReq.Address2, createReq.Phone))));
         }
         catch (Exception ex)
         {
             _logger.LogError(ex.Message);
             return(BadRequest(ex.Message));
         }
     }
 }
        public void TestCreateOrganizationRequest()
        {
            string json = @"{
  ""name"": ""my-org-name"",
  ""quota_definition_guid"": ""4abc3bfe-4f49-488d-bea7-3e0763b110fd""
}";

            CreateOrganizationRequest request = new CreateOrganizationRequest();

            request.Name = "my-org-name";
            request.QuotaDefinitionGuid = new Guid("4abc3bfe-4f49-488d-bea7-3e0763b110fd");
            string result = JsonConvert.SerializeObject(request, Formatting.None);

            Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result);
        }
예제 #12
0
        public void TestCreateOrganizationRequest()
        {
            string json = @"{
  ""name"": ""my-org-name"",
  ""quota_definition_guid"": ""df0b2a62-58ed-46dc-be08-73d30826d4e7""
}";

            CreateOrganizationRequest request = new CreateOrganizationRequest();

            request.Name = "my-org-name";
            request.QuotaDefinitionGuid = new Guid("df0b2a62-58ed-46dc-be08-73d30826d4e7");
            string result = JsonConvert.SerializeObject(request, Formatting.None);

            Assert.AreEqual(TestUtil.ToUnformatedJsonString(json), result);
        }
예제 #13
0
        public async Task <CreateOrganizationResponse> CreateOrganizationAsync(CreateOrganizationRequest request, ClaimsPrincipal claim)
        {
            log?.LogDebug("Request creating an organization!");

            var response = new CreateOrganizationResponse();

            if (claim == null || claim.Identity == null || string.IsNullOrEmpty(claim.Identity.Name))
            {
                response.Status = CreateOrganizationResponse.CreateOrgaStatusCodes.Error;
                log?.LogDebug($"The given claim was not valid.");
                return(response);
            }

            log?.LogInformation($"{claim.Identity.Name} wants to create the organization {request.Name}");

            var user = await userManager.GetUserAsync(claim);

            if (user == null)
            {
                response.Status = CreateOrganizationResponse.CreateOrgaStatusCodes.Error;
                log?.LogDebug($"User was not found to create the organization.");
                return(response);
            }

            if (!IsNameAvailable(request.Name))
            {
                response.Status = CreateOrganizationResponse.CreateOrgaStatusCodes.NameTaken;
                log?.LogDebug($"Organization Name: {request.Name} was already taken!");
                return(response);
            }

            if (!IsShortAvailable(request.ShortName))
            {
                response.Status = CreateOrganizationResponse.CreateOrgaStatusCodes.ShortTaken;
                log?.LogDebug($"Organization Short: {request.ShortName} was already taken!");
                return(response);
            }

            var createdOrganization = CreateOrganization(request.Name, request.ShortName, user);

            if (createdOrganization != null)
            {
                response.OrganizationId = createdOrganization.OrganizationId;
                log?.LogDebug($"Organization {request.Name} with the id {createdOrganization.OrganizationId} has been created!");
            }
            return(response);
        }
        /// <summary>
        /// Creating an Organization
        /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/250/organizations/creating_an_organization.html"</para>
        /// </summary>
        public async Task <CreateOrganizationResponse> CreateOrganization(CreateOrganizationRequest value)
        {
            UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget);

            uriBuilder.Path = "/v2/organizations";
            var client = this.GetHttpClient();

            client.Uri    = uriBuilder.Uri;
            client.Method = HttpMethod.Post;


            client.Content = ((string)JsonConvert.SerializeObject(value)).ConvertToStream();
            var expectedReturnStatus = 201;
            var response             = await this.SendAsync(client, expectedReturnStatus);

            return(Utilities.DeserializeJson <CreateOrganizationResponse>(await response.Content.ReadAsStringAsync()));
        }
예제 #15
0
        /// <summary>
        /// Creating an Organization
        /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/195/organizations/creating_an_organization.html"</para>
        /// </summary>
        public async Task <CreateOrganizationResponse> CreateOrganization(CreateOrganizationRequest value)
        {
            UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget);

            uriBuilder.Path = "/v2/organizations";
            var client = this.GetHttpClient();

            client.Uri    = uriBuilder.Uri;
            client.Method = HttpMethod.Post;
            client.Headers.Add(await BuildAuthenticationHeader());
            client.ContentType = "application/x-www-form-urlencoded";
            client.Content     = JsonConvert.SerializeObject(value).ConvertToStream();
            var expectedReturnStatus = 201;
            var response             = await this.SendAsync(client, expectedReturnStatus);

            return(Utilities.DeserializeJson <CreateOrganizationResponse>(await response.ReadContentAsStringAsync()));
        }
        public async Task <OrganizationCreationResponse> CreateOrganization(CreateOrganizationRequest request)
        {
            using (var a = contextFactory.CreateDbContext())
            {
                var existingUser = await a.Users.Where(x => x.Email == request.Email).FirstOrDefaultAsync();

                if (existingUser != null)
                {
                    throw new ArgumentException("Each email can only participate in 1 organization");
                }

                if (await a.Organizations.FirstOrDefaultAsync(x => x.Name.ToLower() == request.OrganizationName.ToLower()) != null)
                {
                    throw new ArgumentException("There is already an organization with that name!");
                }

                var org = new Organizations()
                {
                    Name = request.OrganizationName
                };

                var password = BC.HashPassword(request.Password);

                var user = new Users()
                {
                    Admin          = true,
                    Activated      = true,
                    Email          = request.Email,
                    FirstName      = request.FirstName,
                    LastName       = request.LastName,
                    OrganizationId = org.Id,
                    HashedPassword = password,
                };

                org.Users.Add(user);

                await a.AddAsync(org);

                await a.SaveChangesAsync();

                var token = generateJwtToken(user);

                return(new OrganizationCreationResponse(user, token, org));
            }
        }
        public void CanCreateOrganizations()
        {
            var orgRepo = new Mock<IOrganizationRepository>();

            var request = new CreateOrganizationRequest
                              {
                                  Name = "My Organization",
                                  ProfileId = "Simtay111"
                              };

            var handler = new CreateOrganizationRequestHandle(orgRepo.Object);

            var response = handler.Handle(request);

            Assert.NotNull(response);

            orgRepo.Verify(x => x.Save(It.Is<Organization>(y => y.Name == request.Name)));
            orgRepo.Verify(x => x.Save(It.Is<Organization>(y => y.CreatorId == request.ProfileId)));
            orgRepo.Verify(x => x.Save(It.Is<Organization>(y => !string.IsNullOrEmpty(y.Id))));
        }
예제 #18
0
        public static void ClassInit(TestContext context)
        {
            client = TestUtil.GetClient();
            CloudCredentials credentials = new CloudCredentials();

            credentials.User     = TestUtil.User;
            credentials.Password = TestUtil.Password;
            try
            {
                client.Login(credentials).Wait();
            }
            catch (Exception ex)
            {
                Assert.Fail("Error while loging in" + ex.ToString());
            }
            CreateOrganizationRequest org = new CreateOrganizationRequest();

            org.Name = "test_" + Guid.NewGuid().ToString();
            var newOrg = client.Organizations.CreateOrganization(org).Result;

            orgGuid = newOrg.EntityMetadata.Guid;

            CreateSpaceRequest spc = new CreateSpaceRequest();

            spc.Name             = "test_" + Guid.NewGuid().ToString();
            spc.OrganizationGuid = orgGuid;
            var newSpace = client.Spaces.CreateSpace(spc).Result;

            spaceGuid = newSpace.EntityMetadata.Guid;

            CreatesSharedDomainDeprecatedRequest r = new CreatesSharedDomainDeprecatedRequest();

            r.Name     = Guid.NewGuid().ToString() + ".com";
            r.Wildcard = true;
            domainGuid = client.DomainsDeprecated.CreatesSharedDomainDeprecated(r).Result.EntityMetadata.Guid;
        }
예제 #19
0
        public void CreateOrganizationTest()
        {
            using (ShimsContext.Create())
            {
                MockClients clients = new MockClients();

                string json = @"{
  ""metadata"": {
    ""guid"": ""d424c3c2-8a40-4f87-8540-b1fecebd602a"",
    ""url"": ""/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a"",
    ""created_at"": ""2015-05-19T15:27:20+00:00"",
    ""updated_at"": null
  },
  ""entity"": {
    ""name"": ""my-org-name"",
    ""billing_enabled"": false,
    ""quota_definition_guid"": ""1e863ed8-2c0b-44a2-bc27-9c670b6bbc39"",
    ""status"": ""active"",
    ""quota_definition_url"": ""/v2/quota_definitions/1e863ed8-2c0b-44a2-bc27-9c670b6bbc39"",
    ""spaces_url"": ""/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/spaces"",
    ""domains_url"": ""/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/domains"",
    ""private_domains_url"": ""/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/private_domains"",
    ""users_url"": ""/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/users"",
    ""managers_url"": ""/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/managers"",
    ""billing_managers_url"": ""/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/billing_managers"",
    ""auditors_url"": ""/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/auditors"",
    ""app_events_url"": ""/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/app_events"",
    ""space_quota_definitions_url"": ""/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/space_quota_definitions""
  }
}";
                clients.JsonResponse = json;

                clients.ExpectedStatusCode = (HttpStatusCode)201;
                var cfClient = clients.CreateCloudFoundryClient();

                CreateOrganizationRequest value = new CreateOrganizationRequest();


                var obj = cfClient.Organizations.CreateOrganization(value).Result;


                Assert.AreEqual("d424c3c2-8a40-4f87-8540-b1fecebd602a", TestUtil.ToTestableString(obj.EntityMetadata.Guid), true);
                Assert.AreEqual("/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a", TestUtil.ToTestableString(obj.EntityMetadata.Url), true);
                Assert.AreEqual("2015-05-19T15:27:20+00:00", TestUtil.ToTestableString(obj.EntityMetadata.CreatedAt), true);
                Assert.AreEqual("", TestUtil.ToTestableString(obj.EntityMetadata.UpdatedAt), true);
                Assert.AreEqual("my-org-name", TestUtil.ToTestableString(obj.Name), true);
                Assert.AreEqual("false", TestUtil.ToTestableString(obj.BillingEnabled), true);
                Assert.AreEqual("1e863ed8-2c0b-44a2-bc27-9c670b6bbc39", TestUtil.ToTestableString(obj.QuotaDefinitionGuid), true);
                Assert.AreEqual("active", TestUtil.ToTestableString(obj.Status), true);
                Assert.AreEqual("/v2/quota_definitions/1e863ed8-2c0b-44a2-bc27-9c670b6bbc39", TestUtil.ToTestableString(obj.QuotaDefinitionUrl), true);
                Assert.AreEqual("/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/spaces", TestUtil.ToTestableString(obj.SpacesUrl), true);
                Assert.AreEqual("/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/domains", TestUtil.ToTestableString(obj.DomainsUrl), true);
                Assert.AreEqual("/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/private_domains", TestUtil.ToTestableString(obj.PrivateDomainsUrl), true);
                Assert.AreEqual("/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/users", TestUtil.ToTestableString(obj.UsersUrl), true);
                Assert.AreEqual("/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/managers", TestUtil.ToTestableString(obj.ManagersUrl), true);
                Assert.AreEqual("/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/billing_managers", TestUtil.ToTestableString(obj.BillingManagersUrl), true);
                Assert.AreEqual("/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/auditors", TestUtil.ToTestableString(obj.AuditorsUrl), true);
                Assert.AreEqual("/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/app_events", TestUtil.ToTestableString(obj.AppEventsUrl), true);
                Assert.AreEqual("/v2/organizations/d424c3c2-8a40-4f87-8540-b1fecebd602a/space_quota_definitions", TestUtil.ToTestableString(obj.SpaceQuotaDefinitionsUrl), true);

            }
        }
        /// <summary>
        ///     Handles the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="response">The response.</param>
        protected override void Handle(CreateOrganizationRequest request, DtoResponse <OrganizationSummaryDto> response)
        {
            var organization = _organizationFactory.Create(request.Name);

            response.DataTransferObject = Mapper.Map <Organization, OrganizationSummaryDto>(organization);
        }
예제 #21
0
 public async Task <IActionResult> CreateOrganization([FromBody] CreateOrganizationRequest createOrganizationRequest)
 {
     return(Ok(new CreateOrganizationResponse(await _OrganizationLogic.CreateOrganizationAsync(createOrganizationRequest?.DisplayName).ConfigureAwait(false))));
 }
 public void CreateRequest(CreateOrganizationRequest request)
 {
     this.createOrganizationRequests.Add(request);
     this.createOrganizationRequests.Save();
 }
예제 #23
0
 /// <summary>
 /// Creating an Organization
 /// <para>For detailed information, see online documentation at: "http://apidocs.cloudfoundry.org/195/organizations/creating_an_organization.html"</para>
 /// </summary>
 public async Task<CreateOrganizationResponse> CreateOrganization(CreateOrganizationRequest value)
 {
     UriBuilder uriBuilder = new UriBuilder(this.Client.CloudTarget);
     uriBuilder.Path = "/v2/organizations";
     var client = this.GetHttpClient();
     client.Uri = uriBuilder.Uri;
     client.Method = HttpMethod.Post;
     var authHeader = await BuildAuthenticationHeader();
     if (!string.IsNullOrWhiteSpace(authHeader.Key))
     {
         client.Headers.Add(authHeader);
     }
     client.ContentType = "application/x-www-form-urlencoded";
     client.Content = JsonConvert.SerializeObject(value).ConvertToStream();
     var expectedReturnStatus = 201;
     var response = await this.SendAsync(client, expectedReturnStatus);
     return Utilities.DeserializeJson<CreateOrganizationResponse>(await response.ReadContentAsStringAsync());
 }
 public void CreateRequest(CreateOrganizationRequest request)
 {
     this.createOrganizationRequests.Add(request);
     this.createOrganizationRequests.Save();
 }