public static void commandManager(string command) { switch (command) { case "create": Console.WriteLine("Введите название создаваемого турнира"); string creatingTournamentName = Console.ReadLine(); Console.WriteLine("Введите имена участников через пробел"); var arrayWithPlayers = Console.ReadLine().Split(' ').ToList(); CreateTournament.createTournament(creatingTournamentName, arrayWithPlayers); getNewCommand(); break; case "next": Console.WriteLine("Введите название турнира"); string updatingTournamentName = Console.ReadLine(); Console.WriteLine("Введите имя победителя"); string winnerName = Console.ReadLine(); NextTour.goToTheNextTour(updatingTournamentName, winnerName); getNewCommand(); break; case "exit": break; default: Console.WriteLine("Ошибка. Несуществующая программа"); break; } }
public async Task CreateTournament() { var newTournament = new CreateTournament(tournaments); await newTournament.Create(); Console.WriteLine("Tournament was successfully created!\n"); while (true) { Console.WriteLine("'0' - Exit to main menu"); Console.WriteLine("'1' - Process to tournament"); lineToRead = Console.ReadLine(); if (lineToRead.Length != 0) { if (lineToRead[0] == '0') { break; } else if (lineToRead[0] == '1') { await ProcessToTournament(tournaments.Last()); } } Console.WriteLine(); } }
public JsonResult Create(CreateTournament command) { command.Id = Guid.NewGuid(); Domain.Dispatcher.SendCommand(command); return(Json(command)); }
public async Task CreateAsync(CreateTournament cmd) { var task = State.TournamentDoesNotExists() switch { Results.Unit => PersistPublishAsync(new TournamentCreated(cmd.Name, cmd.TournamentId, cmd.TraceId, cmd.InvokerUserId)), Results x => PublishErrorAsync(new ErrorHasOccurred((int)x, x.ToString(), cmd.TraceId, cmd.InvokerUserId)) }; await task; }
public async Task <ActionResult> Create(CreateTournament command) { if (ModelState.IsValid) { await CommandDispatcher.DispatchAsync(command); this.HttpContext.Response.StatusCode = 201; return(RedirectToAction("Index", new { message = "JUPI udalo sie utworzyc nowy turniej", status = "success" })); } ViewBag.Message = "NIe udalo sie stworzyc turnieju"; return(View()); }
public async Task <IActionResult> CreateTournament([FromBody] TournamenWriteDto tournament) { var createTournament = new CreateTournament(tournament.Title, tournament.StartDate, tournament.EndDate); var isCompletedSuccessfully = await _mediator.Send(createTournament); if (isCompletedSuccessfully) { return(Ok()); } else { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } }
public static async Task <Models.TournamentElement> PostTournamentAsync(this ITournaments operations, CreateTournament model, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.PostTournamentWithHttpMessagesAsync(model, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
public static Models.TournamentElement PostTournament(this ITournaments operations, CreateTournament model) { return(operations.PostTournamentAsync(model).GetAwaiter().GetResult()); }
public int createTournament(CreateTournament tournament) { Tournament tourToCreate = new Tournament(); var allTeams = dataManager.getAllTeams(); foreach (var team in allTeams) { if (tournament.TeamNames.Contains(team.Name)) { tourToCreate.Teams.Add(team); } } tourToCreate.Name = tournament.Name; tourToCreate.hostPlayerID = tournament.hostPlayerID; var tournamentId = dataManager.CreateTournament(tourToCreate.hostPlayerID, tourToCreate.Name, tourToCreate.Teams[0], tournament.Description, tournament.TournamentSizeTeams); for (int i = 0; i < tournament.TournamentSizeTeams - 1; i++) { TournamentMatch tmpMatch = new TournamentMatch(); tmpMatch.tournamentId = tournamentId; tourToCreate.Matches.Add(tmpMatch); } double numberOfRounds = System.Math.Sqrt(tournament.TournamentSizeTeams); var RealRounds = Math.Ceiling(numberOfRounds); var filledRound = 1; List <TournamentMatch> matchesToSet = new List <TournamentMatch>(); double matchesLeft = tourToCreate.Matches.Count / 2.0; matchesToSet = tourToCreate.Matches.GetRange(0, Convert.ToInt32(Math.Ceiling(matchesLeft))); int matchCount = 0; while (filledRound != RealRounds + 1) { setTournamentGameRound(filledRound, matchesToSet); matchCount += matchesToSet.Count; filledRound++; matchesLeft = matchesLeft / 2; if (matchesLeft > 0.5) { matchesToSet = tourToCreate.Matches.GetRange(matchCount, Convert.ToInt32(Math.Ceiling(matchesLeft))); } } int nofrg = tourToCreate.Matches.Where(o => o.TournamentRound == 1).Count(); int j = 0; for (int i = 0; i < tourToCreate.Teams.Count; i++) { tourToCreate.Matches[j].teamOne = tourToCreate.Teams[i]; if (tourToCreate.Teams.Count > i + 1) { tourToCreate.Matches[j].teamTwo = tourToCreate.Teams[i + 1]; } i++; j++; } foreach (var match in tourToCreate.Matches) { if (match.teamOne == null || match.teamOne.Name == "") { match.teamOne = new Team(); match.teamOne.Name = "Unknown"; } if (match.teamTwo == null || match.teamTwo.Name == "") { match.teamTwo = new Team(); match.teamTwo.Name = "Unknown"; } dataManager.createTournamentGame(match); } if (tournamentId > 0) { foreach (var team in tourToCreate.Teams) { dataManager.AddTeamToTournament(team.Id, tournamentId); } return(tournamentId); } else { return(0); } }
public async Task <HttpOperationResponse <Models.TournamentElement> > PostTournamentWithHttpMessagesAsync(CreateTournament tournament, Dictionary <string, List <string> > customHeaders = null, CancellationToken cancellationToken = default(CancellationToken)) { if (tournament == null) { throw new ValidationException(ValidationRules.CannotBeNull, "tournament"); } if (tournament != null) { tournament.Validate(); } // Tracing bool _shouldTrace = ServiceClientTracing.IsEnabled; string _invocationId = null; if (_shouldTrace) { _invocationId = ServiceClientTracing.NextInvocationId.ToString(); Dictionary <string, object> tracingParameters = new Dictionary <string, object>(); tracingParameters.Add("tournament", tournament); tracingParameters.Add("api_key", Client.ApiKey); tracingParameters.Add("cancellationToken", cancellationToken); ServiceClientTracing.Enter(_invocationId, this, "PostTournament", tracingParameters); } // Construct URL var _baseUrl = Client.BaseUri.AbsoluteUri; var _url = new System.Uri(new System.Uri(_baseUrl + (_baseUrl.EndsWith("/") ? "" : "/")), "v1/tournaments.json").ToString(); List <string> _queryParameters = new List <string>(); if (Client.ApiKey != null) { _queryParameters.Add(string.Format("api_key={0}", System.Uri.EscapeDataString(Client.ApiKey))); } if (_queryParameters.Count > 0) { _url += "?" + string.Join("&", _queryParameters); } // Create HTTP transport objects var _httpRequest = new HttpRequestMessage(); HttpResponseMessage _httpResponse = null; _httpRequest.Method = new HttpMethod("POST"); _httpRequest.RequestUri = new System.Uri(_url); // Set Headers if (customHeaders != null) { foreach (var _header in customHeaders) { if (_httpRequest.Headers.Contains(_header.Key)) { _httpRequest.Headers.Remove(_header.Key); } _httpRequest.Headers.TryAddWithoutValidation(_header.Key, _header.Value); } } // Serialize Request string _requestContent = null; if (tournament != null) { _requestContent = Microsoft.Rest.Serialization.SafeJsonConvert.SerializeObject(tournament, Client.SerializationSettings); _httpRequest.Content = new StringContent(_requestContent, System.Text.Encoding.UTF8); _httpRequest.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json; charset=utf-8"); } // Send Request if (_shouldTrace) { ServiceClientTracing.SendRequest(_invocationId, _httpRequest); } cancellationToken.ThrowIfCancellationRequested(); _httpResponse = await Client.HttpClient.SendAsync(_httpRequest, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); if (_shouldTrace) { ServiceClientTracing.ReceiveResponse(_invocationId, _httpResponse); } HttpStatusCode _statusCode = _httpResponse.StatusCode; cancellationToken.ThrowIfCancellationRequested(); string _responseContent = null; if ((int)_statusCode != 200) { var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'", _statusCode)); if (_httpResponse.Content != null) { _responseContent = await _httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false); } else { _responseContent = string.Empty; } ex.Request = new HttpRequestMessageWrapper(_httpRequest, _requestContent); ex.Response = new HttpResponseMessageWrapper(_httpResponse, _responseContent); if (_shouldTrace) { ServiceClientTracing.Error(_invocationId, ex); } _httpRequest.Dispose(); if (_httpResponse != null) { _httpResponse.Dispose(); } throw ex; } // Create Result var _result = new HttpOperationResponse <Models.TournamentElement>(); _result.Request = _httpRequest; _result.Response = _httpResponse; // Deserialize Response if ((int)_statusCode == 200) { _result.Body = Microsoft.Rest.Serialization.SafeJsonConvert.DeserializeObject <Models.TournamentElement>(_responseContent, Client.DeserializationSettings); } if (_shouldTrace) { ServiceClientTracing.Exit(_invocationId, _result); } return(_result); }
public async Task <IActionResult> Post([FromBody] CreateTournament command) { await CommandDispatcher.DispatchAsync(command); return(Created($"tournaments/{command.Name}", new object())); }