protected override async Task HandleRequirementAsync(AuthorizationHandlerContext context, TeamLeaderRequirement requirement) { if (requirement.AllowAdmin && context.User.HasClaim(AppClaimTypes.Role, AppRoles.Administrator)) { context.Succeed(requirement); return; } if ((requirement.AllowLootMaster && context.User.HasClaim(AppClaimTypes.Role, AppRoles.LootMaster)) || (requirement.AllowRaidLeader && context.User.HasClaim(AppClaimTypes.Role, AppRoles.RaidLeader)) || (requirement.AllowRecruiter && context.User.HasClaim(AppClaimTypes.Role, AppRoles.Recruiter))) { long?teamId = context.Resource switch { long id => id, TeamDto team => team.Id, _ => null }; if (teamId is null || await _permissionManager.IsLeaderOfAsync(teamId.Value)) { context.Succeed(requirement); } } } }
public IEnumerable <TeamDto> SearchTeams(string name) { IEnumerable <Team> teams = teamService.SearchTeams(name); var teamDtos = teams.Select(t => TeamDto.FromTeam(t)); return(teamDtos); }
public async Task <IActionResult> Post(SearchTeamPostData postData) { string memberID = this.HttpContext.Session.GetObject <string>(CommonFlagHelper.CommonFlag.SessionFlag.MemberID); try { TeamDto teamDto = new TeamDto() { SearchKey = postData.SearchKey, ExecutorID = memberID }; ResponseResultDto responseResult = await this.teamService.SearchTeam(teamDto); if (responseResult.Ok) { return(Ok(responseResult.Data)); } return(BadRequest(responseResult.Data)); } catch (Exception ex) { this.logger.LogError($"Search Team Error >>> ExecutorID:{memberID} SearchKey:{postData.SearchKey}\n{ex}"); return(BadRequest("搜尋車隊發生錯誤.")); } }
// GET: api/Teams public IEnumerable <TeamDto> GetTeams() { var teams = teamService.GetTeams(); var teamDtos = teams.Select(t => TeamDto.FromTeam(t)); return(teamDtos); }
private NbaGameDto CreateGameDtoWithoutPlayers(NbaShortGame nbaShortGame) { Guid gameId = nbaShortGame.GameId; DateTime startDateTime = nbaShortGame.StartDateTime; Guid homeTeamId = nbaShortGame.HomeTeamId; Guid awayTeamId = nbaShortGame.AwayTeamId; TeamDto homeTeam = GetTeam(homeTeamId); TeamDto awayTeam = GetTeam(awayTeamId); List <PlayerDto> homePlayerList = GetPlayers(homeTeamId); List <PlayerDto> awayPlayerList = GetPlayers(awayTeamId); homeTeam.PlayerList = homePlayerList; awayTeam.PlayerList = awayPlayerList; NbaGameDto nbaGameDto = new NbaGameDto { GameId = gameId, StartDateTime = startDateTime, HomeTeam = homeTeam, AwayTeam = awayTeam }; return(nbaGameDto); }
public static TeamMatchDto AssembleDto(this TeamMatch match, TeamDto homeEntrant, TeamDto awayEntrant) { var dto = new TeamMatchDto { ID = match.ID, FixtureID = match.TeamFixture.ID, CompetitionID = match.TeamFixture.CompetitionID, CompetitionStageSequence = match.TeamFixture.CompetitionRound.CompetitionEvent.CompetitionStage.Sequence, Leg = match.Leg, Date = match.Date, MatchStatusID = match.MatchStatusID, MatchCalculationEngineID = match.MatchCalculationEngineID, Pitch = match.Pitch.AssembleDto(), HomeEntrant = homeEntrant, AwayEntrant = awayEntrant, VenueTypeID = match.VenueTypeID, Comment = match.Comment }; dto.Round = match.TeamFixture.CompetitionRound.AssembleTeamDto(); if (match.MatchStatusID.IsProcessedWithResult()) { dto.HomeResult = match.AssembleMatchHomeScore(); dto.AwayResult = match.AssembleMatchAwayScore(); foreach (TeamMatchXGame playerMatchGame in match.Games) { var gameDto = playerMatchGame.Game.AssembleDto(); dto.Games.Add(gameDto); } } return(dto); }
public TeamDto CreateTeamDto(Team team) { var stadiumDto = this.CreateStadiumDto(team.Stadium); var cityDto = this.CreateCityDto(team.City); var countryDto = this.CreateCountryDto(team.Country); var presidentDto = this.CreatePresidentDto(team.FootballPresident); var managersDto = this.CreateManagerDtoCollection(team.FootballManagers); var playersDto = this.CreatePlayerDtoCollection(team.FootballPlayers); var teamDto = new TeamDto() { Id = team.Id, Name = team.Name, Alias = team.Alias, Established = team.Established, Region = team.Region, Division = team.Division, Trophies = team.Trophies, PlayedMatches = team.PlayedMatches, WonMatches = team.WonMatches, LostMatches = team.LostMatches, Stadium = stadiumDto, City = cityDto, Captain = team.Captain, Country = countryDto, FootballPresident = presidentDto, FootballManagers = managersDto, FootballPlayers = playersDto }; return(teamDto); }
public Team CreateTeamFromDto(TeamDto teamDto) { var managers = this.CreateManagerCollection(teamDto.FootballManagers, teamDto.Id); var players = this.CreatePlayerCollection(teamDto.FootballPlayers, teamDto.Id); var team = new Team() { Name = teamDto.Name, Alias = teamDto.Alias, Established = teamDto.Established, Region = teamDto.Region, Division = teamDto.Division, Trophies = teamDto.Trophies, Captain = teamDto.Captain, PlayedMatches = teamDto.PlayedMatches, WonMatches = teamDto.WonMatches, LostMatches = teamDto.LostMatches, StadiumId = teamDto.Stadium.Id, CountryId = teamDto.Country.Id, CityId = teamDto.City.Id, FootballPresidentId = teamDto.FootballPresident.Id, FootballManagers = managers, FootballPlayers = players }; return(team); }
public async Task <IActionResult> RejectJoin(RejectApplyForJoinPostData postData) { string memberID = this.HttpContext.Session.GetObject <string>(CommonFlagHelper.CommonFlag.SessionFlag.MemberID); try { TeamDto teamDto = new TeamDto() { TeamID = postData.TeamID, ExaminerID = memberID, TargetID = postData.TargetID }; ResponseResultDto responseResult = await this.teamService.RejectApplyForJoinTeam(teamDto); if (responseResult.Ok) { return(Ok(responseResult.Data)); } return(BadRequest(responseResult.Data)); } catch (Exception ex) { this.logger.LogError($"Reject Apply For Join Team Error >>> TeamID:{postData.TeamID} ExaminerID:{memberID} TargetID:{postData.TargetID}\n{ex}"); return(BadRequest("拒絕申請加入車隊發生錯誤.")); } }
/// <summary> /// 搜尋車隊 /// </summary> /// <param name="teamDto">teamDto</param> /// <returns>ResponseResultDto</returns> public async Task<ResponseResultDto> SearchTeam(TeamDto teamDto) { try { string postData = JsonConvert.SerializeObject(teamDto); HttpResponseMessage httpResponseMessage = await Utility.ApiPost(AppSettingHelper.Appsetting.ServiceDomain.Service, "api/Team/SearchTeam", postData); if (httpResponseMessage.IsSuccessStatusCode) { return new ResponseResultDto() { Ok = true, Data = await httpResponseMessage.Content.ReadAsAsync<IEnumerable<TeamSimpleInfoViewDto>>() }; } return new ResponseResultDto() { Ok = false, Data = await httpResponseMessage.Content.ReadAsAsync<string>() }; } catch (Exception ex) { this.logger.LogError($"Search Team Error >>> ExecutorID:{teamDto.ExecutorID} SearchKey:{teamDto.SearchKey}\n{ex}"); return new ResponseResultDto() { Ok = false, Data = "搜尋車隊發生錯誤." }; } }
public IHttpActionResult FindTeamForPlayer(int id) { //Finds the first team which has any players //that match the input playerid Team Team = db.Teams .Where(t => t.Players.Any(p => p.PlayerID == id)) .FirstOrDefault(); //if not found, return 404 status code. if (Team == null) { return(NotFound()); } //put into a 'friendly object format' TeamDto TeamDto = new TeamDto { TeamID = Team.TeamID, TeamName = Team.TeamName, TeamBio = Team.TeamBio }; //pass along data as 200 status code OK response return(Ok(TeamDto)); }
public bool UpdateTeam(TeamDto teamDto) { if (teamDto == null) { GenerateFaultException("UpdateTeam", "ArgumentException"); } var parameters = new List <Parameter>(); parameters.Add(new Parameter { Type = DbType.Int32, Name = "@TeamId", Value = teamDto.TeamId }); parameters.Add(new Parameter { Type = DbType.String, Name = "@Name", Value = teamDto.Name }); parameters.Add(new Parameter { Type = DbType.Int32, Name = "@CountryId", Value = teamDto.CountryId }); parameters.Add(new Parameter { Type = DbType.String, Name = "@SportId", Value = teamDto.SportId }); var connection = new Connection <TeamDto>(); try { return(connection.GetConnectionUpdate(CommandType.StoredProcedure, "UpdateTeam", parameters)); } catch (SqlException sqlEx) { var exception = new CustomException(); exception.Title = "UpdateTeam"; log.Error(sqlEx.Message); throw new FaultException <CustomException>(exception, sqlEx.Message); } }
public async Task <Guid> AddAsync(TeamDto dto) { var reference = await context.References.FirstOrDefaultAsync(x => x.Competition == dto.Competition && x.Type == ReferenceType.Team && x.ReferenceValue == dto.ReferenceId); if (reference != null) { throw new ItemAlreadyExistException($"Team with id {dto.ReferenceId} already exsits."); } if (dto.Id == Guid.Empty) { dto.Id = Guid.NewGuid(); } await context.References.AddAsync(new Reference { Competition = dto.Competition, Type = ReferenceType.Team, LocalValue = dto.Id.ToString().ToLowerInvariant(), ReferenceValue = dto.ReferenceId, Timestamp = DateTime.Now }); await context.Teams.AddAsync(mapper.Map <Team>(dto)); await context.SaveChangesAsync(); return(dto.Id); }
public Team ToTeam(TeamDto teamDto) { var sport = new Sport { SportId = teamDto.SportId, Name = teamDto.Sport }; var country = new Country { CountryId = teamDto.CountryId, Name = teamDto.Country }; var team = new Team { TeamId = teamDto.TeamId, Name = teamDto.Name, SportId = teamDto.SportId, Sport = sport, CountryId = teamDto.CountryId, Country = country }; return(team); }
public string Execute(IList <string> commandArgs) { if (!AuthenticationManager.IsAuthenticated()) { throw new InvalidOperationException(Messages.LoginFirst); } UserDto invitee = AuthenticationManager.GetCurrentUser(); if (commandArgs.Count != Constants.DeclineInviteCommandArgumentsCount) { throw new FormatException(Messages.InvalidArgumentsCount); } string teamName = commandArgs[0]; TeamDto team = TeamController.GetTeam(teamName); if (team == null) { throw new ArgumentException(String.Format(Messages.TeamNotExist, teamName)); } if (!InvitationController.InvitationExists(team.Id, invitee.Id)) { throw new ArgumentException(String.Format( Messages.InvitationNotExist, teamName, invitee.Username)); } InvitationController.RemoveInvitation(team.Id, invitee.Id); return(String.Format(Messages.InvitationDeclined, invitee.Username, teamName)); }
public async Task DeleteTeam(int id) { TeamDto teamDto = await GetTeam(id); DBContext.Remove(teamDto); await DBContext.SaveChangesAsync(); }
public Task SaveTeam(TeamDto teamDto) { using (var session = NHibernateHelper.OpenSession()) { using (session.BeginTransaction()) { var id = teamDto.Id; Team team; if (id == 0) { team = new Team(); } else { team = session.Query <Team>().Where(x => x.Id == id).First(); } team.DisplayName = teamDto.DisplayName; team.Name = teamDto.Name; session.SaveOrUpdate(team); session.Transaction.Commit(); return(Task.CompletedTask); } } }
// public async Task<IActionResult> AddTeam(Team team, int roomId, int parentTeamId) public async Task <IActionResult> AddTeam(int roomId, int parentTeamId, TeamDto teamDto) { try { var userId = userService.GetUserId(); // var newTeam = await teamService.AddTeam(team, roomId, userId,parentTeamId); var user = await userService.getUserById(userId); var team = mapper.Map <Team>(teamDto); var newTeam = await teamService.AddTeam(team, roomId, userId, parentTeamId); var JoinChatOfTeam = await teamChatService.GetTeamChatOfTeam(newTeam.Id); // await chatHub.Clients.Group(JoinChatOfTeam.ChatName).SendAsync("ReceiveMessageOnJoin", $"User: {user.UserName} Join Group of {JoinChatOfTeam} "); //Not Show to New User That Join *Must Saved inHistory // await chatHub.Groups.AddToGroupAsync(chatHub.Clients.User(userId), JoinChatOfTeam.ChatName); //add to Group to tell Clients on Group new User Come var parentTeam = await teamService.GetTeamOnlyById(parentTeamId); // var notification = notificationService.CreateNewNotificaition(new Notification // { // Content = $"the leader of team {parentTeam.Name} accept your request to creatث a sub team from this team", // UserId = userId // }); // await notificationHub.Clients.User(userId).SendAsync("recievenotification",notification); return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <ActionResult <bool> > Update(Guid teamid, TeamDto teamDto) { try { var teamx = await _teamRepo.GetTeam(teamid); if (teamx == null) { return(BadRequest($"could not find team with id: {teamid}")); } teamx.Description = teamDto.Description ?? teamx.Description; teamx.Teamnumber = teamDto.Teamnumber ?? teamx.Teamnumber; var res = await _teamRepo.SaveAll(); var teamxToReturn = _mapper.Map <TeamDto>(teamx); return(Ok(teamxToReturn)); } catch (Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.InnerException.Message)); } }
// GET: Player/Details/5 public ActionResult Details(int id) { ShowPlayer ViewModel = new ShowPlayer(); string url = "playerdata/findplayer/" + id; HttpResponseMessage response = client.GetAsync(url).Result; //Can catch the status code (200 OK, 301 REDIRECT), etc. //Debug.WriteLine(response.StatusCode); if (response.IsSuccessStatusCode) { //Put data into player data transfer object PlayerDto SelectedPlayer = response.Content.ReadAsAsync <PlayerDto>().Result; ViewModel.player = SelectedPlayer; url = "playerdata/findteamforplayer/" + id; response = client.GetAsync(url).Result; TeamDto SelectedTeam = response.Content.ReadAsAsync <TeamDto>().Result; ViewModel.team = SelectedTeam; return(View(ViewModel)); } else { return(RedirectToAction("Error")); } }
public async Task <IActionResult> Post(TeamDto dto) { var team = _mapper.Map <Team>(dto); await _teamService.AddAsync(team); return(Created("localhost", "")); }
public static async Task WrapInAsync(this TeamDto dto, Team team, HemaneContext context) { team.Name = dto.Name; team.Club = await context.Clubs.SingleAsync(c => c.Id == dto.ClubId); team.League = await context.Leagues.SingleAsync(l => l.Id == dto.LeagueId); }
public UpdateOutput <TeamDto, long> Update(UpdateTeamInput input) { TeamRepository.Includes.Add(r => r.LastModifierUser); TeamRepository.Includes.Add(r => r.CreatorUser); TeamRepository.Includes.Add(r => r.PlayerCareers); Team currentTeamEntity = TeamRepository.Get(input.Entity.Id); if (currentTeamEntity == null) { throw new CityQuestItemNotFoundException(CityQuestConsts.CityQuestItemNotFoundExceptionMessageBody, "\"Team\""); } if (!TeamPolicy.CanUpdateEntity(currentTeamEntity)) { throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionUpdateDenied, "\"Team\""); } TeamRepository.Detach(currentTeamEntity); Team newTeamEntity = input.Entity.MapTo <Team>(); newTeamEntity.IsDefault = currentTeamEntity.IsDefault; TeamRepository.Update(newTeamEntity); TeamDto newTeamDto = (TeamRepository.Get(newTeamEntity.Id)).MapTo <TeamDto>(); TeamRepository.Includes.Clear(); return(new UpdateOutput <TeamDto, long>() { UpdatedEntity = newTeamDto }); }
/// <summary> /// Remove all the user specific details from the teamdto when the user is not authenticated /// </summary> public static void TeamPlayerDetails(IRequest request, IResponse response, TeamDto team) { if (request.GetSession().HasRole(RoleNames.Admin, HostContext.Resolve <IUserAuthRepository>())) { return; } if (request.GetSession().IsAuthenticated) { using (var db = HostContext.Resolve <IDbConnectionFactory>().Open()) { var currentUserId = Convert.ToInt32(request.GetSession().UserAuthId); var isUserPlayingInTheSameLeague = db.Select <Team>(sql => (sql.Player1Id == currentUserId || sql.Player2Id == currentUserId) && sql.LeagueId == team.League.Id).Any(); if (isUserPlayingInTheSameLeague) { return; } } } team.Player1.Email = string.Empty; team.Player1.PhoneNumber = string.Empty; team.Player2.Email = string.Empty; team.Player2.PhoneNumber = string.Empty; }
public async Task AddTeam(TeamDto teamDto) { Team team = mapper.Map <Team>(teamDto); await dbContext.Teams.AddAsync(team); await dbContext.SaveChangesAsync(); }
public CreateOutput <TeamDto, long> Create(CreateTeamInput input) { Team newTeamEntity = input.Entity.MapTo <Team>(); if (!TeamPolicy.CanCreateEntity(newTeamEntity)) { throw new CityQuestPolicyException(CityQuestConsts.CQPolicyExceptionCreateDenied, "\"Team\""); } newTeamEntity.IsActive = true; newTeamEntity.IsDefault = false; TeamRepository.Includes.Add(r => r.LastModifierUser); TeamRepository.Includes.Add(r => r.CreatorUser); TeamRepository.Includes.Add(r => r.PlayerCareers); TeamDto newTeamDto = (TeamRepository.Insert(newTeamEntity)).MapTo <TeamDto>(); TeamRepository.Includes.Clear(); return(new CreateOutput <TeamDto, long>() { CreatedEntity = newTeamDto }); }
public TeamDto GetlTeamsById(int id) { TeamDto result = null; try { result = _utilServices.Team .Select(x => new TeamDto { Id = x.Codigo, Descripcion = x.Descripcion, Proyecto = x.Proyecto.Pro_I_Codigo.ToString(), CantidadIntegrantes = x.CantidadIntegrantes, Estado = x.Estado, FechaCreacion = x.FechaCreacion }).Where(x => x.Id == id).Single(); } catch (Exception ex) { _utilServices.Errores.Add(ex.SaveModel()); _utilServices.SaveChanges(); throw ex; } return(result); }
public async Task <bool> Add(TeamDto teamDto) { if (string.IsNullOrWhiteSpace(teamDto.Name) || string.IsNullOrWhiteSpace(teamDto.Manager)) { return(false); } var teamCountry = await _context.Countries.FindAsync(teamDto.CountryId); if (teamCountry == null) { return(false); } var team = new Team { Name = teamDto.Name, Manager = teamDto.Manager, Country = teamCountry, }; _context.Teams.Add(team); await _context.SaveChangesAsync(); return(true); }
public IActionResult Delete(TeamDto team) { var model = _mapper.Map <TeamDto, Team>(team); _repository.Delete(model); return(new NoContentResult()); }
public async Task <IActionResult> Post(CreateTeamPostData postData) { string memberID = this.HttpContext.Session.GetObject <string>(CommonFlagHelper.CommonFlag.SessionFlag.MemberID); try { TeamDto teamDto = new TeamDto() { TeamName = postData.TeamName, CityID = postData.CityID, TeamInfo = postData.TeamInfo, SearchStatus = postData.SearchStatus, ExamineStatus = postData.ExamineStatus, FrontCoverUrl = postData.FrontCoverUrl, PhotoUrl = postData.PhotoUrl, ExecutorID = memberID }; ResponseResultDto responseResult = await this.teamService.CreateTeam(teamDto); if (responseResult.Ok) { return(Ok(responseResult.Data)); } return(BadRequest(responseResult.Data)); } catch (Exception ex) { this.logger.LogError($"Create Team Error >>> MemberID:{memberID} PostData:{JsonConvert.SerializeObject(postData)}\n{ex}"); return(BadRequest("建立車隊發生錯誤.")); } }
public int SaveTeam(TeamDto team) { using (var con = new SqlConnection(ConnectionString)) { con.Open(); if (team.Id == 0) { var p = con.Query<int>("INSERT INTO Team(Name,CreatedDate,CreatedByID) VALUES (@name,@dt,@createdById);SELECT CAST(SCOPE_IDENTITY() as int)", new { @name = team.Name, @dt = DateTime.Now, @createdById = team.CreatedById }); team.Id = p.First(); con.Execute("INSERT INTO TeamMember(MemberID,TeamId,CreatedDate,CreatedByID) VALUES (@memberId,@teamId,@dt,@createdById)", new { memberId = team.CreatedById, @teamId = team.Id, @dt = DateTime.Now, @createdById = team.CreatedById }); } else { con.Query<int>("UPDATE Team SET Name=@name WHERE Id=@id", new { @name = team.Name, @id = team.Id }); } return team.Id; } }
public Team(TeamDto dto, Site site) { _dto = dto; _site = site; _agentColl = new List<Agent>(); }
public Team CreateAndAddTeam(TeamDto teamDto) { Team team = new Team(teamDto, this); teamColl.Add(team); return team; }