コード例 #1
0
        private void Parse(string value)
        {
            Reservation.Clear();
            var games = WpEventDeserialize.Parse(value);

            if (games != null)
            {
                games.OrderBy(e => e.Name).ToList().ForEach(res => Reservation.Add(res));
            }
        }
コード例 #2
0
        public List <WPUser> GetBookingOptions(int wpEventId, Game game)
        {
            var selectedGameWpId      = game.WordPressTagOs.Split(';');
            var currentWpEvent        = _context.WPEvent.Include(e => e.WPBookings).ThenInclude(e => e.WPUser).Where(e => e.Id == wpEventId).ToList();
            List <WPBooking> bookings = currentWpEvent.SelectMany(e => e.WPBookings).ToList();
            List <WPUser>    users    = new List <WPUser>();

            foreach (var booking in bookings)
            {
                var reservations = WpEventDeserialize.Parse(booking.Meta);
                if (reservations != null)
                {
                    var gamesReservation = reservations.Where(e => e.Valid).Select(e => e.Name);
                    if (selectedGameWpId.Any(e => gamesReservation.Contains(e)))
                    {
                        users.Add(booking.WPUser);
                    }
                }
            }
            return(users);
        }
コード例 #3
0
        public string CreateChallonge(int gameId, int wpEventId, IList <WPUser> additionalPlayers)
        {
            var selectedGame     = _context.Game.FirstOrDefault(e => e.Id == gameId);
            var selectedGameWpId = selectedGame.WordPressTag.Split(';');
            var currentWpEvent   = _context.WPEvent.Include(e => e.WPBookings).ThenInclude(e => e.WPUser)
                                   .Where(e => e.Id == wpEventId);
            var users     = currentWpEvent.SelectMany(e => e.WPBookings.Select(u => u.WPUser));
            var useradded = new List <WPUser>();


            if (selectedGame != null)
            {
                var currentEvent = currentWpEvent.FirstOrDefault();
                var eventDate    = currentEvent.Date?.ToString("dd/MM/yy");

                var remove        = currentEvent.Date?.ToString("Mdyy");
                var url           = $"{remove}{selectedGame.Id}";
                var selectedEvent = FormatCurrentEventName(currentEvent.Name);
                var tournament    = AddTournament(eventDate, selectedEvent, selectedGame, url, currentEvent);


                foreach (var booking in currentEvent.WPBookings)
                {
                    var reservations = WpEventDeserialize.Parse(booking.Meta);
                    if (reservations != null)
                    {
                        var gamesReservation = reservations.Where(e => e.Valid).Select(e => e.Name);
                        if (selectedGameWpId.Any(e => gamesReservation.Contains(e)))
                        {
                            try
                            {
                                useradded.Add(booking.WPUser);
                                _challongeProvider.AddPlayer(tournament.id, booking.WPUser.Name);
                            }
                            catch
                            {
                                Console.WriteLine($"Erreur d ajout sur {booking.WPUser.Name}");
                                continue;
                            }
                        }
                    }
                }

                if (additionalPlayers != null && additionalPlayers.Count > 0)
                {
                    foreach (var additionalPlayer in additionalPlayers)
                    {
                        if (useradded.All(e => e.Name != additionalPlayer.Name))
                        {
                            _challongeProvider.AddPlayer(tournament.id, additionalPlayer.Name);
                        }
                    }
                }


                return(tournament.url);
            }


            return("error while creating challonge");
        }