public async Task <Customer> Upsert(Customer item) { var proxyUrl = SfProxyMagic.GetServiceProxy(this._serviceContext, item.Name); using (var response = await this._httpClient.PostAsync(proxyUrl, new StringContent(JsonConvert.SerializeObject(item), Encoding.UTF8, "application/json"))) { if (response.IsSuccessStatusCode) { var responseData = await response.Content.ReadAsStringAsync(); var newCustomer = JsonConvert.DeserializeObject <Customer>(responseData); return(newCustomer); } } return(null); }
public async Task <bool> Delete(string id) { var partitions = await this._fabricClient.QueryManager.GetPartitionListAsync(SfProxyMagic.GetDataServiceName(this._serviceContext)); foreach (Partition partition in partitions) { var proxyUrl = SfProxyMagic.GetServiceProxy(this._serviceContext, ((Int64RangePartitionInformation)partition.PartitionInformation).LowKey, id); using (var response = await this._httpClient.DeleteAsync(proxyUrl)) { if (response.StatusCode == System.Net.HttpStatusCode.OK) { return(true); } } } return(false); }
public async Task <Customer> Get(string id) { var partitions = await this._fabricClient.QueryManager.GetPartitionListAsync(SfProxyMagic.GetDataServiceName(this._serviceContext)); foreach (Partition partition in partitions) { var proxyUrl = SfProxyMagic.GetServiceProxy(this._serviceContext, ((Int64RangePartitionInformation)partition.PartitionInformation).LowKey, id); using (var response = await this._httpClient.GetAsync(proxyUrl)) { if (response.StatusCode != System.Net.HttpStatusCode.OK) { continue; } var result = await response.Content.ReadAsStringAsync(); return(JsonConvert.DeserializeObject <Customer>(result)); } } return(null); }
public async Task <IEnumerable <CustomerListView> > GetAll(Func <CustomerListView, bool> whereFunc = null) { var partitions = await this._fabricClient.QueryManager.GetPartitionListAsync(SfProxyMagic.GetDataServiceName(this._serviceContext)); var result = new List <CustomerListView>(); foreach (Partition partition in partitions) { var proxyUrl = SfProxyMagic.GetServiceProxy(this._serviceContext, ((Int64RangePartitionInformation)partition.PartitionInformation).LowKey); using (var response = await this._httpClient.GetAsync(proxyUrl)) { if (response.StatusCode != System.Net.HttpStatusCode.OK) { continue; } result.AddRange(JsonConvert.DeserializeObject <List <CustomerListView> >(await response.Content.ReadAsStringAsync())); } } return(result); }