public async Task <string> CreateUserAsync(CreateUserOptions options, [FromServices] StateClient state) { string id = Guid.NewGuid().ToString(); var user = UserActorProxy.CreateProxy(id); await user.SetDetailsAsync( new UserDetails { Email = options.Email, Name = options.Name }); var users = await state.GetStateAsync <HashSet <string> >("users"); var emails = await state.GetStateAsync <Dictionary <string, string> >("emails"); users ??= new HashSet <string>(); emails ??= new Dictionary <string, string>(); users.Add(id); emails[options.Email] = id; await state.SaveStateAsync("users", users); await state.SaveStateAsync("emails", emails); var deckManager = DeckManagerProxy.CreateProxy(); await deckManager.CreateRandomDeckAsync(new CreateRandomDeckOptions { Name = "My Starter Deck", UserId = id }); return(id); }
public async Task <string> CreateGameAsync([FromBody] CreateGameOptions options, [FromServices] StateClient state) { // TODO: Verify user owns the deck. string id = Guid.NewGuid().ToString(); var deck = DeckActorProxy.CreateProxy(options.DeckId); var deckDetails = await deck.GetDetailsAsync(); var cards = await Task.WhenAll( deckDetails.Cards.Select( async deckCard => { var card = CardActorProxy.CreateProxy(deckCard.CardId); var cardDetails = await card.GetDetailsAsync(); return(new GameCard { CardId = deckCard.CardId, Value = cardDetails.Value }); })); var game = GameActorProxy.CreateProxy(id); await game.SetDetailsAsync( new GameDetails { Players = new[] { new GamePlayer { Cards = cards, UserId = options.UserId }, CreateComputerPlayer(cards.Length) } }); var games = await state.GetStateAsync <HashSet <string> >("games"); games ??= new HashSet <string>(); games.Add(id); await state.SaveStateAsync("games", games); var user = UserActorProxy.CreateProxy(options.UserId); await user.AddGameAsync(id); return(id); }
public async Task SetCardAsync(string id, [FromBody] CardDetails details, [FromServices] StateClient state) { var proxy = CardActorProxy.CreateProxy(id); await proxy.SetDetailsAsync(details); var cards = await state.GetStateAsync <HashSet <string> >("cards"); cards ??= new HashSet <string>(); cards.Add(id); await state.SaveStateAsync("cards", cards); }
public async Task SetDeckAsync(string id, [FromBody] DeckDetails details, [FromServices] StateClient state) { var deck = DeckActorProxy.CreateProxy(id); await deck.SetDetailsAsync(details); var decks = await state.GetStateAsync <HashSet <string> >("decks"); decks ??= new HashSet <string>(); decks.Add(id); await state.SaveStateAsync("decks", decks); }
public async Task SetGameAsync(string id, [FromBody] GameDetails details, [FromServices] StateClient state) { string actorType = "GameActor"; var actorId = new ActorId(id); var actorProxy = ActorProxy.Create <IGameActor>(actorId, actorType); await actorProxy.SetDetailsAsync(details); var games = await state.GetStateAsync <HashSet <string> >("games"); games ??= new HashSet <string>(); games.Add(id); await state.SaveStateAsync("games", games); }
public async Task AddOneWithoutStateEntry([FromServices] StateClient state, [FromState("testStore")] Widget widget) { widget.Count++; await state.SaveStateAsync("testStore", (string)this.HttpContext.Request.RouteValues["widget"], widget); }
public async Task Post([FromBody] Order value) { await _stateClient.SaveStateAsync(value.ID, value); }