public async Task AddProduct(Shopping.Products.Models.Products p) { var products = await _stateManager.GetOrAddAsync <IReliableDictionary <Guid, Shopping.Products.Models.Products> >("products"); using (var tx = _stateManager.CreateTransaction()) { await products.AddOrUpdateAsync(tx, p.ProductID, p, (ProductID, value) => p); await tx.CommitAsync(); } }
/// <summary> /// This is the main entry point for your service replica. /// This method executes when this replica of your service becomes primary and has write status. /// </summary> /// <param name="cancellationToken">Canceled when Service Fabric needs to shut down this service replica.</param> protected override async Task RunAsync(CancellationToken cancellationToken) { // TODO: Replace the following sample code with your own logic // or remove this RunAsync override if it's not needed in your service. _repository = new ProductRepository(this.StateManager); var product1 = new Shopping.Products.Models.Products { ProductID = Guid.NewGuid(), Name = " Monitor", Price = 500, Availability = 100 }; await _repository.AddProduct(product1); var p = _repository.GetAllProducts(); }