private async void ContentDialog_PrimaryButtonClick(ContentDialog sender, ContentDialogButtonClickEventArgs args) { var request = new CreateTeamRequest { Name = TeamNameBox.Text, UserId = HttpApi.LoggedInUser.Id }; try { var createTeam = await HttpApi.Team.SaveAsync(request, HttpApi.AuthToken); await HttpApi.Role.AssignRoleAsync(new AssignRoleRequest { RoleId = 1, TeamId = createTeam.Id, UserId = HttpApi.LoggedInUser.Id }, HttpApi.AuthToken); var getTeam = await HttpApi.Team.GetAsync(createTeam.Id, HttpApi.AuthToken); callback(getTeam); } catch (ApiException ex) { await ex.ShowErrorDialog(); } }
public CreateTeamResponse CreateTeam(CreateTeamRequest request)//TODO: fix bug with assigned user role { var response = new CreateTeamResponse(); var dbTeam = new TeamEntity { TeamName = request.Team.TeamName, ProjectManagerId = request.UserId }; try { uow.Repository <TeamEntity>().Add(dbTeam); uow.Save(); var dbXrefUserTeam = new XrefUserTeamEntity { TeamId = dbTeam.TeamId, UserId = request.UserId }; uow.Repository <XrefUserTeamEntity>().Add(dbXrefUserTeam); uow.Save(); response.Success = true; response.TeamId = dbTeam.TeamId; response.UserId = request.UserId; } catch (Exception ex) { response.ErrorMessage = ex.Message; response.Success = false; } return(response); }
public IHttpActionResult CreateTeam(Int32 eventID, Int32 tournamentID, CreateTeamRequest request) { BaseViewModel viewmodel = new BaseViewModel(); TournamentDataController dataCtrl = new TournamentDataController(); SeatDataController seatDataCtrl = new SeatDataController(); TournamentTeamDataController teamDataCtrl = new TournamentTeamDataController(); TournamentTeamParticipantDataController teamParticipantDataCtrl = new TournamentTeamParticipantDataController(); try { if (seatDataCtrl.GetCurrentUserSeats(eventID).FindAll(x => x.State >= 2).Count == 0) { return(Error(viewmodel, "Du bist kein Teilnehmer dieser Veranstaltung. Bitte reserviere einen Platz.")); } var team = teamDataCtrl.Insert(request.ToModel(tournamentID)); JoinTournamentRequest _tmp = new JoinTournamentRequest() { TeamID = team.ID }; teamParticipantDataCtrl.Insert(_tmp.ToTeamModel()); } catch (Exception ex) { return(Error(viewmodel, ex)); } return(Ok(viewmodel, "Team wurde erstellt.")); }
public void MapCreateTeamRequestShouldSucceed() { // Arrange var name = "Test"; var image = "Image"; var description = "Descriptor"; var layout = Guid.NewGuid().ToString(); var apiVersion = "1.0"; // Act var request = new CreateTeamRequest(new CreateTeamFromQuery() { ApiVersion = apiVersion }, new CreateTeamFromBody() { Name = name, Image = image, Description = description, Layout = layout }); var command = new CreateTeamCommand(name, image, description, layout); var mappedCommand = _cqsMapper.Map(request); // Assert command.Should().BeEquivalentTo(mappedCommand); }
public async Task <IActionResult> AddTeam([FromBody] CreateTeamRequest request) { var cmd = _mapper.Map <CreateTeamCommand>(request); await _commandSender.Send(cmd); return(Ok()); }
public IActionResult CreateTeam(TeamVM newTeam) { if (!ModelState.IsValid) { throw new Exception("Model invalid"); } int userId = 0; if (Int32.TryParse(HttpContext.Session.GetString("UserId"), out userId)) { var request = new CreateTeamRequest { Team = new Team { TeamName = newTeam.TeamName }, UserId = userId }; var response = service.CreateTeam(request); if (response.Success) { return(RedirectToAction("UserDashboard")); } ViewBag.Error = response.ErrorMessage; } return(View()); }
public async Task <IActionResult> Create([FromQuery] CreateTeamFromQuery query, [FromBody] CreateTeamFromBody body) { var request = new CreateTeamRequest(query, body); var result = await _apiResult.Produce(request); return(result); }
public async Task <IActionResult> Produce(CreateTeamRequest request) { var validatorActionResult = await _validationArrangement.Validate(request); var actionResult = await _operationArrangement.Process(request, validatorActionResult); return(actionResult); }
public async Task Post([FromBody] CreateTeamRequest request) { await _createTeamCommandHandler.Execute( new CreateTeamCommand { TeamId = request.TeamId, Name = request.Name }); }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> protected override void Handle(CreateTeamRequest request, DtoResponse <TeamSummaryDto> response) { var team = _teamFactory.Create(request.OrganizationKey, request.Name); if (team != null) { response.DataTransferObject = Mapper.Map <Team, TeamSummaryDto> (team); } }
public CreateTeamCommand Map(CreateTeamRequest request) { var command = new CreateTeamCommand(request.Name, request.Image, request.Description, request.Layout); return(command); }
/// <summary> /// Handles the specified request. /// </summary> /// <param name="request">The request.</param> /// <param name="response">The response.</param> protected override void Handle(CreateTeamRequest request, DtoResponse <TeamSummaryDto> response) { var organization = _organizationRepository.GetByKey(UserContext.OrganizationKey); var team = _teamFactory.Create(organization, request.Name); if (team != null) { response.DataTransferObject = Mapper.Map <Team, TeamSummaryDto> (team); } }
public static TournamentTeam ToModel(this CreateTeamRequest request, Int32 TournamentID) { TournamentTeam model = new TournamentTeam(); model.Name = request.Name; model.Password = !String.IsNullOrEmpty(request.Password) ? request.Password : null; model.TournamentID = TournamentID; return(model); }
public void createTeamRequest(Action <PomeloException, CreateTeamResponse> cb, object option = null) { var request = new CreateTeamRequest(); _socket.request <CreateTeamResponse>(request, (object msg, out int s2c_code, out string s2c_msg) => { var rsp = msg as CreateTeamResponse; s2c_code = rsp.s2c_code; s2c_msg = rsp.s2c_msg; return(s2c_code == 200); }, cb, option); }
public Team CreateTeam(CreateTeamRequest request) { var team = new Infrastructure.Team { Name = request.Name, Context = request.Context, WorkerTeams = new List <WorkerTeam>() }; _databaseContext.Teams.Add(team); _databaseContext.SaveChanges(); return(team.ToDomain()); }
public TeamResponse ExecutePost(CreateTeamRequest request) { if (_databaseGateway.GetTeamByTeamName(request.Name) != null) { throw new PostTeamException($"Team with name \"{request.Name}\" already exists"); } var team = _teamGateway.CreateTeam(request); return(team.ToResponse()); }
public ConfirmationResponse Execute(CreateTeamRequest request) { request.ThrowExceptionIfInvalid(); var entity = ToDomainModel(request); var result = _teamRepository.Create(entity); return(new ConfirmationResponse("Team successfully created.") { Id = result }); }
public void ConstructorShouldSucceed() { // Arrange var query = new CreateTeamFromQuery(); var body = new CreateTeamFromBody(); // Act var request = new CreateTeamRequest(query, body); // Assert request.Should().NotBeNull(); }
public async Task <int> CreateTeamAsync( CreateTeamRequest request, CancellationToken cancellationToken = default) { try { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (string.IsNullOrEmpty(request.Name)) { throw new ArgumentException(); } bool isNameTaken = await _context.Teams.AnyAsync(t => t.Name == request.Name); if (isNameTaken) { throw new ArgumentException("There is already team with the same name."); } var teamEntity = new Entities.Team { Name = request.Name }; var rankEntity = new Entities.Rank { // Starting points Points = 0, }; teamEntity.Rank = rankEntity; _context.Teams.Add(teamEntity); await _context.SaveChangesAsync(cancellationToken); return(teamEntity.Id); } catch (ServiceException) { throw; } catch (Exception ex) { _logger.LogError(ex, "Error creating team."); throw Conversion.ConvertException(ex); } }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post")] CreateTeamRequest request, TraceWriter log) { try { if (string.IsNullOrWhiteSpace(request.GroupId)) { throw new ArgumentException("Parameter cannot be null", "GroupId"); } dynamic team = new ExpandoObject(); var content = new StringContent(JsonConvert.SerializeObject(team), Encoding.UTF8, "application/json"); log.Info(JsonConvert.SerializeObject(team)); Uri uri = new Uri($"https://graph.microsoft.com/beta/groups/{request.GroupId}/team"); log.Info(uri.AbsoluteUri); string bearerToken = await ConnectADAL.GetBearerToken(); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", bearerToken); var response = await client.PutAsync(uri, content); if (response.IsSuccessStatusCode) { string responseBody = await response.Content.ReadAsStringAsync(); dynamic responseJson = JObject.Parse(responseBody); return(await Task.FromResult(new HttpResponseMessage(HttpStatusCode.OK) { Content = new ObjectContent <CreateTeamResponse>(new CreateTeamResponse { Created = true, TeamUrl = responseJson.webUrl }, new JsonMediaTypeFormatter()) })); } string responseMsg = await response.Content.ReadAsStringAsync(); log.Info(responseMsg); dynamic errorMsg = JsonConvert.DeserializeObject(responseMsg); return(await Task.FromResult(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable) { Content = new ObjectContent <CreateTeamResponse>(new CreateTeamResponse { Created = false, ErrorMessage = errorMsg }, new JsonMediaTypeFormatter()) })); } catch (Exception e) { log.Error(e.Message); return(await Task.FromResult(new HttpResponseMessage(HttpStatusCode.ServiceUnavailable) { Content = new ObjectContent <string>(e.Message, new JsonMediaTypeFormatter()) })); } }
public void CreateTeamRequest_AsEntity_NoParticipants_ReturnsEmptyList() { //Arrange var request = new CreateTeamRequest { Name = "Test", Participants = null }; //Act var team = request.AsEntity(); //Assert Assert.IsEmpty(team.Participants); }
public async Task <IActionResult> PostAsync([FromForm] CreateTeamRequest request) { await _service.AddAsync( User.GetUserId(), request.Title, request.SubTitle, //request.Country, "Россия", request.City, request.About, request.PhoneNumber, request.Photo?.ToStorageFile()); return(Ok()); }
public async Task <ActionResult <CreateTeamResponse> > CreateTeam([FromBody] CreateTeamRequest createTeamRequest, CancellationToken cancellationToken) { var team = new Team() { Name = createTeamRequest.Name, FoundedIn = createTeamRequest.FoundedIn }; await _teamsRepository.AddAsync(team, cancellationToken); var response = new CreateTeamResponse { Team = _mapper.Map <TeamDto>(team) }; return(Ok(response)); }
public void Handle(CreateTeamRequest request) { try { if (!String.IsNullOrEmpty(request.NameTeam) || !String.IsNullOrEmpty(request.IdFirstMember) || !String.IsNullOrEmpty(request.IdSecondMember)) { if (_teamRepo.Any(x => x.NameTeam.Contains(request.NameTeam) && !x.IsDeleted)) { var response = new CreateTeamResponse(false); Sender.Tell(response); _logger.Error("Couldn't create Team: {0}: This name is exists", request.NameTeam); } else { _teamRepo.Insert(new Team { NameTeam = request.NameTeam, FirstMember = GetPlayerById(request.IdFirstMember), SecondMember = GetPlayerById(request.IdSecondMember), IsDeleted = false }); var response = new CreateTeamResponse(true); Sender.Tell(response); _logger.Info("Create Team successfull: {0}", request.NameTeam); } } else { var response = new CreateTeamResponse(false); Sender.Tell(response); _logger.Error("Couldn't create Team: {0} {1}: All fields are required", request.NameTeam); } } catch (Exception ex) { var response = new CreateTeamResponse(false); Sender.Tell(response); _logger.Error("Couldn't create Team: {0} {1}: ", request.NameTeam, ex.Message); } }
public ActionResult CreateTeam(CreateTeamModel model) { var request = new CreateTeamRequest { MaxSize = model.MaxSize, Name = model.Name, ProfileId = GetProfileFromCookie() }; var handler = new CreateTeamRequestHandle(new TeamRepository()); var response = handler.Handle(request); if (response.Status != ResponseCodes.Success) throw new NotImplementedException(); return RedirectToAction("Index"); }
public async Task <IActionResult> CreateTeam([FromBody] CreateTeamRequest request, CancellationToken cancellationToken) { var command = new CreateTeamCommand ( request.Name ); var @event = await _commandDispatcher.DispatchAsync(command, cancellationToken); var location = Url.RouteUrl("FindTeam", new { teamId = @event.TeamId }, null, Request.Host.Value); Response.Headers["Location"] = location; var response = new CreateTeamResponse(@event.TeamId.ToString()); return(StatusCode(201, response)); }
public async Task <IActionResult> Process(CreateTeamRequest request, IValidatorActionResult validatorActionResult) { IActionResult actionResult; if (validatorActionResult.Result == null) { var command = _cqsMapper.Map(request); var result = await _mediator.Send(command); actionResult = result.IsFailure ? _apiResponse.Fail(result) : _apiResponse.Created($"/api/teams/{((Result<Guid>)result).Value}", result.Version.ToString()); } else { actionResult = validatorActionResult.Result; } return(actionResult); }
public async Task <long> CreateTeam(CreateTeamRequest team) { WriteDocument doc = new WriteDocument { Template = new Template() }; doc.Template.Data.Add(new Data() { Name = "name", Value = team.Name }); doc.Template.Data.Add(new Data() { Name = "sport_id", Value = team.SportId }); doc.Template.Data.Add(new Data() { Name = "location_country", Value = team.LocationCountry }); doc.Template.Data.Add(new Data() { Name = "time_zone", Value = team.IANATimeZone }); doc.Template.Data.Add(new Data() { Name = "location_postal_code", Value = team.LocationPostalCode }); HttpResponseMessage resp = await _httpClient.PostAsJsonAsync("/teams", doc); string str = await resp.Content.ReadAsStringAsync(); ReadDocument rDoc = JsonConvert.DeserializeObject <ReadDocument>(str); if (resp.IsSuccessStatusCode) { return(rDoc.UnpackTeams().First().Id); } else { throw new HttpRequestException(rDoc.Collection.Error.Message); } }
public IActionResult CreateTeam([FromBody] CreateTeamRequest request) { var validator = new CreateTeamRequestValidator(); var validationResults = validator.Validate(request); if (!validationResults.IsValid) { return(BadRequest(validationResults.ToString())); } try { var createdTeam = _teamsUseCase.ExecutePost(request); return(CreatedAtAction(nameof(CreateTeam), createdTeam)); } catch (PostTeamException e) { return(UnprocessableEntity(e.Message)); } }
public ActionResult <CreateTeamResponse> CreateTeam(CreateTeamRequest request) { var response = new CreateTeamResponse() { ResponseMessage = Models.ResponseMessage.Failure }; int?stadiumId = request.Team.StadiumId == 0 ? null : request.Team.StadiumId; _context.Teams.Add(new Team(request.Team.Name, request.Team.Nickname, request.Team.Location, stadiumId)); var success = _context.SaveChanges(); if (success > 0) { response.ResponseMessage = Models.ResponseMessage.Success; } return(Ok(response)); }
public Task <CreateTeamResponse> CreateTeamAsync(CreateTeamDataModel createTeamDataModel, CancellationToken cancellationToken = default(CancellationToken)) => Task.Run(async() => { if (!CrossConnectivity.Current.IsConnected) { throw new InvalidOperationException(AppConsts.ERROR_INTERNET_CONNECTION); } CreateTeamRequest createTeamRequest = new CreateTeamRequest { AccessToken = GlobalSettings.Instance.UserProfile.AccesToken, Url = GlobalSettings.Instance.Endpoints.TeamEndPoints.CreateTeamEndPoint, Data = createTeamDataModel }; CreateTeamResponse createTeamResponse = null; try { createTeamResponse = await _requestProvider.PostAsync <CreateTeamRequest, CreateTeamResponse>(createTeamRequest); } catch (ServiceAuthenticationException exc) { _identityUtilService.RefreshToken(); throw exc; } catch (HttpRequestExceptionEx exc) { CreateTeamBadResponse createTeamBadResponse = JsonConvert.DeserializeObject <CreateTeamBadResponse>(exc.Message); string output = string.Format("{0}", createTeamBadResponse.Name?.FirstOrDefault()); output = (string.IsNullOrWhiteSpace(output) || string.IsNullOrEmpty(output)) ? TeamService.CREATE_NEW_TEAM_COMMON_ERROR_MESSAGE : output; throw new InvalidOperationException(output.Trim()); } catch (Exception ex) { Crashes.TrackError(ex); throw; } return(createTeamResponse); }, cancellationToken);