Exemplo n.º 1
0
        private static Uri SaveParticipant(CompetitionDetail competition, CoupleDetail selectedCouple)
        {
            Uri newParticipantUri = null;

            do
            {
                // choose start number
                Console.Write("Enter start number: ");
                string startNumber = Console.ReadLine();
                int    startNumberValue;
                int.TryParse(startNumber, out startNumberValue);

                ParticipantCoupleDetail participant = new ParticipantCoupleDetail()
                {
                    CompetitionId = competition.Id,
                    CoupleId      = selectedCouple.Id,
                    StartNumber   = startNumberValue
                };

                try
                {
                    newParticipantUri = apiClient.SaveCoupleParticipant(participant);
                }
                catch (ApiException ex)
                {
                    Console.WriteLine(ex.InnerException.Message);
                    continue;
                }
            } while (false);

            return(newParticipantUri);
        }
Exemplo n.º 2
0
        public Uri SaveCouple(CoupleDetail couple)
        {
            if (couple == null)
            {
                throw new ArgumentNullException("couple");
            }

            return(SaveResource <CoupleDetail>(couple, "couple"));
        }
Exemplo n.º 3
0
        public bool UpdateCouple(CoupleDetail couple)
        {
            if (couple == null)
            {
                throw new ArgumentNullException("couple");
            }

            return(UpdateResource <CoupleDetail>(couple, string.Format("couple/{0}", couple.Id)));
        }
Exemplo n.º 4
0
        ///<inheritdoc/>
        public bool UpdateCouple(CoupleDetail couple)
        {
            if (couple == null)
            {
                throw new ArgumentNullException(nameof(couple));
            }

            return(UpdateResource(couple, "couple/" + couple.Id));
        }
Exemplo n.º 5
0
        private static CoupleDetail ChooseCouple()
        {
            // pick one couple
            CoupleDetail selectedCouple = null;

            do
            {
                Console.Write("Enter couple ID: ");
                string coupleId = Console.ReadLine();

                try
                {
                    selectedCouple = apiClient.GetCouple(coupleId);
                }
                catch (ApiException ex)
                {
                    Console.WriteLine(ex.InnerException.Message);
                }
            } while (selectedCouple == null);

            Console.WriteLine();

            return(selectedCouple);
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            // prepare the client for access
            apiClient = new Client("guest", "guest", WdsfEndpoint.Sandbox);

            Console.Write("Enter competition ID:");
            int competitionId;

            if (!int.TryParse(Console.ReadLine(), out competitionId))
            {
                Console.WriteLine("Not a valid competition ID");
                Console.ReadKey();
                return;
            }

            CompetitionDetail competition = apiClient.GetCompetition(competitionId);

            Console.WriteLine(
                "Registering for competition {0} {1} {2} in {3}-{4} on {5}",
                competition.CompetitionType,
                competition.AgeClass,
                competition.Discipline,
                competition.Location,
                competition.Country,
                competition.Date);

            Console.WriteLine("Starting registration.");
            competition.Status = "Registering";
            if (!apiClient.UpdateCompetition(competition))
            {
                Console.WriteLine(string.Format("Failed to start registration. {0}", apiClient.LastApiMessage));
                Console.ReadKey();
                return;
            }

            // we want to list only couples that are allowed to participate in this competition
            string allAllowedAgeGroups = GetAllowedAgeGroups(competition);

            // prepare the couple filter
            Dictionary <string, string> coupleFilter = new Dictionary <string, string>()
            {
                { FilterNames.Couple.NameOrMin, string.Empty },
                { FilterNames.Couple.Division, competition.Division },
                { FilterNames.Couple.AgeGroup, allAllowedAgeGroups }
            };

            do
            {
                // ask for an athlete name and list all possible couples
                ListCouples(coupleFilter);

                // choose one couple id from the list
                CoupleDetail selectedCouple = ChooseCouple();

                // and save the couple as a new participant
                Uri newParticipantUri = SaveParticipant(competition, selectedCouple);

                // get the newly created participant to display it
                ParticipantCoupleDetail participant = apiClient.Get <ParticipantCoupleDetail>(newParticipantUri);

                Console.WriteLine("Added couple '{0}' to competition with ID:{1}.", participant.Name, participant.Id);
                Console.Write("An more? [Y]es/[N]o :");
            } while (Console.ReadKey().Key == ConsoleKey.Y);

            Console.WriteLine("Closing registration.");
            competition.Status = "RegistrationClosed";
            if (!apiClient.UpdateCompetition(competition))
            {
                Console.WriteLine(string.Format("Failed to close registration. {0}", apiClient.LastApiMessage));
                Console.ReadKey();
                return;
            }

            // show all registered participants of this competition
            ListAllParticipants(competition);

            Console.ReadKey();
        }