public async Task StartVote(string maps)
        {
            var user = await this.GetCurrentUserAsync();

            if (this.cache.GetActiveVotes().Count(c => c.StartingUser == user.UserName) > 2)
            {
                await Clients.Caller.SendAsync("Alert", "Mehr als 3 offene Votes am Stück sind nicht erlaubt.");

                return;
            }

            var mapList = maps.Split("\n", StringSplitOptions.RemoveEmptyEntries).Select(c => new VoteItem()
            {
                Name      = c,
                VoteCount = 0,
                Id        = Guid.NewGuid()
            }).ToArray();

            var mapVote = new MapVote()
            {
                Maps         = mapList,
                VoteStart    = DateTime.UtcNow,
                PlayersVoted = new List <Guid>(),
                Id           = Guid.NewGuid(),
                StartingUser = user.UserName
            };

            this.cache.AddVote(mapVote);

            await Clients.All.SendAsync("ReceiveVoteStarted", mapVote, user.UserName);
        }
Beispiel #2
0
 public void AddVote(MapVote mapVote)
 {
     this.cache.Set(this.GetMapVoteKey(mapVote.Id), mapVote, TimeSpan.FromMinutes(30));
     activeVotes.TryAdd(mapVote.Id, true);
 }