public Stock CreateStock(Stock stock, string stockKey = null) { if(!string.IsNullOrWhiteSpace(stockKey)) stock = new LockedStock(stock, stockKey); if (stock.Id.Equals(Guid.Empty)) stock.Id = Guid.NewGuid(); var result = _client.Index(stock); if (result.Created || result.IsValid) return stock; return null; }
public async Task<Guid> Post() { using (var tempStream = GetTempFileStream()) { await Request.Body.CopyToAsync(tempStream); string storageKey = Retry.Do(() => { tempStream.Position = 0; return StorageAdapter.Create(tempStream); }, TimeSpan.FromMilliseconds(200)); Stock stock = new Stock(); stock.ExternalStorageKey = storageKey; var stockKey = GetStockKeyFromHeaders(); stock = DataProvider.CreateStock(stock, stockKey); return stock.Id; } }
public LockedStock(Stock stock, string key) { Id = stock.Id; ExternalStorageKey = stock.ExternalStorageKey; Key = key; }
public bool UpdateStock(Guid id, Stock stock, string stockKey = null) { var existing = RetrieveStock(id, stockKey); if (existing == null) return false; existing.ExternalStorageKey = stock.ExternalStorageKey; var result = _client.Index(existing); return result.IsValid && !result.Created; }