public TeamDTO BuildTeam(CreateTeamResponse data) { TeamDTO teamDTO = null; if (data != null) { teamDTO = new TeamDTO() { Coach = data.Coach, CoachId = data.CoachId, CreatedBy = data.CreatedBy, Events = data.Events, Games = data.Games, Id = data.Id, Locations = data.Locations, Members = data.Members, Name = data.Name, Opponents = data.Opponents, Organization = data.Organization, OrganizationId = data.OrganizationId, Owner = data.Owner, Sport = data.Sport }; } return(teamDTO); }
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 void Handle(EditTeamRequest request) { try { if (!String.IsNullOrEmpty(request.NameTeam) || !String.IsNullOrEmpty(request.IdFirstMember) || !String.IsNullOrEmpty(request.IdSecondMember)) { var team = _teamRepo.Get(request.Id); team.NameTeam = request.NameTeam; team.FirstMember = GetPlayerById(request.IdFirstMember); team.SecondMember = GetPlayerById(request.IdSecondMember); _teamRepo.Replace(team); var response = new EditTeamResponse(true); Sender.Tell(response); _logger.Info("Edit Team successfull: {0} {1}", team.NameTeam); } else { var response = new CreateTeamResponse(false); Sender.Tell(response); _logger.Error("Couldn't create Team: {0}: All fields are required", request.NameTeam); } } catch (Exception ex) { var response = new EditTeamResponse(false); Sender.Tell(response); _logger.Error("Couldn't Team by id: {0}: {1}", request.Id, ex.Message); } }
public TeamMemberViewModel CreateItem(CreateTeamResponse createTeamResponse) { return(new TeamMemberViewModel { Sport = createTeamResponse.Sport, Owner = createTeamResponse.Organization?.DisplayName, Team = createTeamResponse.Name, Joined = DateTime.Now, CanBeDeleted = createTeamResponse.CreatedBy?.Id == GlobalSettings.Instance.UserProfile.Id }); }
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 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 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);
public async Task <ActionResult <CreateTeamResponse> > UpdateTeam([FromRoute] int teamId, [FromBody] UpdateTeamRequest createTeamRequest, CancellationToken cancellationToken) { var team = await _teamsRepository.GetByIdAsync(teamId, cancellationToken); if (team != null) { team.Name = createTeamRequest.Name; team.FoundedIn = createTeamRequest.FoundedIn; await _teamsRepository.UpdateAsync(team, cancellationToken); var response = new CreateTeamResponse() { Team = _mapper.Map <TeamDto>(team) }; return(Ok(response)); } else { return(BadRequest()); } }