예제 #1
0
        public async Task <int> Run()
        {
            using (var db = LiteDbFactory.New())
            {
                var configCollection = db.GetCollection <Config>();
                var config           = configCollection.FindAll().SingleOrDefault() ?? new Config();

                options.ApplyToConfig(config);

                if (!config.LeagueId.HasValue)
                {
                    Console.Error.WriteLine("Error: League ID is not set");

                    return(1);
                }

                if (!config.TeamId.HasValue)
                {
                    Console.Error.WriteLine("Error: Team ID is not set");

                    return(1);
                }

                var client = new YahooClient(config);

                var addPlayers = await client.SearchPlayers(config.LeagueId.Value, addNameOrId);

                var dropPlayers = await client.SearchPlayers(config.LeagueId.Value, dropNameOrId);

                if (VerifySinglePlayer(addPlayers, "add") && VerifySinglePlayer(dropPlayers, "drop"))
                {
                    var claimsCollection = db.GetCollection <Claim>();
                    var existingClaims   = claimsCollection.FindAll();

                    var claim = new Claim
                    {
                        Add      = new Player(addPlayers.Single()),
                        Drop     = new Player(dropPlayers.Single()),
                        Priority = existingClaims
                                   .OrderByDescending(ec => ec.Priority)
                                   .Select(ec => ec.Priority)
                                   .FirstOrDefault() + 1
                    };

                    claimsCollection.Insert(claim);

                    Console.WriteLine("Claim successfully added");

                    claimsCollection.FindAll().ToArray().WriteTable();

                    return(0);
                }
                else
                {
                    return(1);
                }
            }
        }
예제 #2
0
        public async Task <int> Run()
        {
            using (var db = LiteDbFactory.New())
            {
                var configCollection = db.GetCollection <Config>();
                var config           = configCollection.FindAll().SingleOrDefault() ?? new Config();

                options.ApplyToConfig(config);

                if (!config.LeagueId.HasValue)
                {
                    Console.Error.WriteLine("Error: League ID is not set");

                    return(1);
                }

                Console.WriteLine("Searching for players...");

                var client = new YahooClient(config);

                var players = await client.SearchPlayers(config.LeagueId.Value, playerNameOrId);

                players.WriteTable();
            }

            return(0);
        }