public void CreateSiteAsync_PassObject_ShouldNotThrowException() { var testJob = new NewSite() { Name = ("AVIA TECHNIQUE LTD"), Phone = (""), Postcode = ("RG41 2QJ"), Region = ("UNITED KINGDOM"), AccountNumber = (null), AccountNumber2 = (null), Address1 = ("UNIT 3 FISHPONDS ESTATE"), Address2 = ("FISHPONDS ROAD"), Address3 = ("WOKINGHAM"), AutoEmail = (false), City = ("BERKSHIRE"), Contact = (""), Coordinate = null, Country = ("GB"), Customer = (1286862), Email = (""), EtaEmailNotifications = (null), EtaSmsNotifications = (null) }; var client = new PodfatherClientV1(GetAPIKey()); client.SetLogger(GetLogger()); var result = Task.Run(async() => await client.CreateSiteAsync(testJob).ConfigureAwait(false)).Result; result.Id.Should().BeGreaterThan(0); }
public string PostCreateSubSites([FromBody] NewSite Site) { try { if (Site != null && !string.IsNullOrEmpty(Site.Name)) { WebCreationInformation wci = new WebCreationInformation(); wci.Url = Site.Name; wci.Title = Site.Name; wci.Description = Site.Name; wci.UseSamePermissionsAsParentSite = true; wci.WebTemplate = "STS#0"; wci.Language = 1033; Web w = context.Site.RootWeb.Webs.Add(wci); context.Load(w, website => website.Url ); context.ExecuteQuery(); return("El sitio " + Site.Name + " fue creado con exito. La URL es " + w.Url); } return("El nombre del sitio no puede ser vacio"); } catch (Exception e) { return(Site.Name + " no pudo ser creado, ya le envie la informacion del error al administrador"); } }
public async Task <Site> CreateSiteAsync(NewSite newSite) { using (var client = HttpClientFactory.CreateClient(serviceUri, accessKey)) { String json = JsonConvert.SerializeObject(newSite, new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-ddThh:mm:ssZ" }); HttpResponseMessage responseMessage = await client.PostAsync("/v1/sites", new StringContentWithoutCharset(json, Encoding.UTF8, "application/json")).ConfigureAwait(false); if (responseMessage.IsSuccessStatusCode) { var responseJson = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); return(JsonConvert.DeserializeObject <SiteContainer>(responseJson).Site); } else { LogDebug("CreateSiteAsync|Received response code: " + responseMessage.StatusCode); throw new HttpResponseException(responseMessage); } } }