public async Task <IActionResult> Put(string name, [FromBody] SmilrEvent value) { try { var dictionary = await this.stateManager.GetOrAddAsync <IReliableDictionary <string, SmilrEvent> >(ValuesDictionaryName); using (ITransaction tx = this.stateManager.CreateTransaction()) { await dictionary.AddAsync(tx, name, value); await tx.CommitAsync(); } } catch (ArgumentException) { return(new ContentResult { StatusCode = 400, Content = $"A value with name '{name}' already exists." }); } catch (FabricNotPrimaryException) { return(new ContentResult { StatusCode = 410, Content = "The primary replica has moved. Please re-resolve the service." }); } catch (FabricException) { return(new ContentResult { StatusCode = 503, Content = "The service was unable to process the request. Please try again." }); } return(this.Ok()); }
public async Task <IActionResult> PutAsync([FromBody] SmilrEvent smilrEvent) { int partitionKey; try { string key = smilrEvent.start; // Should we validate this in the UI or here in the controller? if (!String.IsNullOrEmpty(key)) { partitionKey = GetPartitionKey(key); } else { throw new ArgumentException("No key provided"); } } catch (Exception ex) { return(new ContentResult { StatusCode = 400, Content = ex.Message }); } //Where var proxyUrl = GetEventStoreUri($"/api/events/{smilrEvent.id}", ServicePartitionKind.Int64Range, partitionKey); //What StringContent putContent = new StringContent(JsonConvert.SerializeObject(smilrEvent), Encoding.UTF8, "application/json"); putContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = await this.httpClient.PutAsync(proxyUrl, putContent); return(new ContentResult() { StatusCode = (int)response.StatusCode, Content = await response.Content.ReadAsStringAsync() }); }