public async Task <IActionResult> Get() { Uri serviceName = Web1.GetBackendServiceName(this.serviceContext); Uri proxyAddress = this.GetProxyAddress(serviceName); ServicePartitionList partitions = await this.fabricClient.QueryManager.GetPartitionListAsync(serviceName); List <KeyValuePair <string, int> > result = new List <KeyValuePair <string, int> >(); foreach (Partition partition in partitions) { string proxyUrl = $"{proxyAddress}/api/staff?PartitionKey={((Int64RangePartitionInformation)partition.PartitionInformation).LowKey}&PartitionKind=Int64Range"; using (HttpResponseMessage response = await this.httpClient.GetAsync(proxyUrl)) { if (response.StatusCode != System.Net.HttpStatusCode.OK) { continue; } result.AddRange(JsonConvert.DeserializeObject <List <KeyValuePair <string, int> > >(await response.Content.ReadAsStringAsync())); } } return(this.Json(result)); }
public async Task <IActionResult> Delete(string staff) { Uri serviceName = Web1.GetBackendServiceName(this.serviceContext); Uri proxyAddress = this.GetProxyAddress(serviceName); long partitionKey = this.GetPartitionKey(staff); string proxyUrl = $"{proxyAddress}/api/staff/{staff}?PartitionKey={partitionKey}&PartitionKind=Int64Range"; using (HttpResponseMessage response = await this.httpClient.DeleteAsync(proxyUrl)) { if (response.StatusCode != System.Net.HttpStatusCode.OK) { return(this.StatusCode((int)response.StatusCode)); } } return(new OkResult()); }
public async Task <IActionResult> Put(string staff) { Uri serviceName = Web1.GetBackendServiceName(this.serviceContext); Uri proxyAddress = this.GetProxyAddress(serviceName); long partitionKey = this.GetPartitionKey(staff); string proxyUrl = $"{proxyAddress}/api/staff/{staff}?PartitionKey={partitionKey}&PartitionKind=Int64Range"; StringContent putContent = new StringContent($"{{ 'staff' : '{staff}' }}", Encoding.UTF8, "application/json"); putContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); using (HttpResponseMessage response = await this.httpClient.PutAsync(proxyUrl, putContent)) { return(new ContentResult() { StatusCode = (int)response.StatusCode, Content = await response.Content.ReadAsStringAsync() }); } }