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 <ActionResult <string> > SignInUserAsync([FromBody] string email, [FromServices] StateClient state) { var emails = await state.GetStateAsync <Dictionary <string, string> >("emails"); if (emails != null && emails.TryGetValue(email, out string userId)) { return(userId); } else { return(Unauthorized()); } }
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 <IEnumerable <string> > GetAsync([FromServices] StateClient state) { var Cards = await state.GetStateAsync <HashSet <string> >("cards"); return(Cards ?? Enumerable.Empty <string>()); }
public async Task <Order> Get(string id) { var order = await _stateClient.GetStateAsync <Order>(id); return(order); }