public IActionResult PutPlayers(int id, Players players) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != players.PlayerId) { return(BadRequest()); } _dystirDBContext.Entry(players).State = EntityState.Modified; try { _dystirDBContext.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PlayersExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(StatusCodes.Status204NoContent)); }
public IActionResult PutSponsors(int id, Sponsors sponsors) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != sponsors.Id) { return(BadRequest()); } db.Entry(sponsors).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!SponsorsExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(StatusCodes.Status204NoContent)); }
private void SetPlayersListByEventsOfMatch(List <EventsOfMatches> eventsOfMatch, Matches selectedMatch) { if (selectedMatch != null) { selectedMatch.HomeTeamScore = eventsOfMatch?.Where(x => (x.EventName?.ToUpper() == "GOAL" || x.EventName?.ToUpper() == "PENALTYSCORED" || x.EventName?.ToUpper() == "OWNGOAL") && x.EventTeam?.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim())?.Count(); selectedMatch.AwayTeamScore = eventsOfMatch?.Where(x => (x.EventName?.ToUpper() == "GOAL" || x.EventName?.ToUpper() == "PENALTYSCORED" || x.EventName?.ToUpper() == "OWNGOAL") && x.EventTeam?.ToUpper().Trim() == selectedMatch.AwayTeam.ToUpper().Trim())?.Count(); selectedMatch.HomeTeamOnTarget = eventsOfMatch?.Where(x => x.EventName?.ToUpper() == "ONTARGET" && x.EventTeam?.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim())?.Count(); selectedMatch.AwayTeamOnTarget = eventsOfMatch?.Where(x => x.EventName?.ToUpper() == "ONTARGET" && x.EventTeam?.ToUpper().Trim() == selectedMatch.AwayTeam.ToUpper().Trim())?.Count(); selectedMatch.HomeTeamCorner = eventsOfMatch?.Where(x => x.EventName?.ToUpper() == "CORNER" && x.EventTeam?.ToUpper().Trim() == selectedMatch.HomeTeam.ToUpper().Trim())?.Count(); selectedMatch.AwayTeamCorner = eventsOfMatch?.Where(x => x.EventName?.ToUpper() == "CORNER" && x.EventTeam?.ToUpper().Trim() == selectedMatch.AwayTeam.ToUpper().Trim())?.Count(); var playersOfMatch = _dystirDBContext.PlayersOfMatches.Where(x => x.MatchId == selectedMatch.MatchID)?.ToList(); foreach (PlayersOfMatches playerOfMatch in playersOfMatch ?? new List <PlayersOfMatches>()) { playerOfMatch.Goal = 0; playerOfMatch.OwnGoal = 0; playerOfMatch.YellowCard = 0; playerOfMatch.RedCard = 0; playerOfMatch.SubIn = -1; playerOfMatch.SubOut = -1; playerOfMatch.Assist = 0; } foreach (EventsOfMatches eventMatch in eventsOfMatch ?? new List <EventsOfMatches>()) { PlayersOfMatches playerOfMatch = playersOfMatch?.FirstOrDefault(x => x.PlayerOfMatchId == eventMatch.MainPlayerOfMatchId); if (playerOfMatch != null) { PlayersOfMatchValuesFromEvent(playerOfMatch, eventMatch); } } _dystirDBContext.SaveChanges(); } }
public IActionResult PutMatches(int id, [FromBody] Matches matches) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != matches.MatchId) { return(BadRequest()); } try { Matches matchInDB = db.Matches.Find(id); if (!(matches.ExtraMinutes == 0 && matches.ExtraSeconds == 0) || matchInDB.StatusId != matches.StatusId) { matches.StatusTime = DateTime.UtcNow.AddMinutes(-matches.ExtraMinutes).AddSeconds(-matches.ExtraSeconds); } db.Entry(matchInDB).CurrentValues.SetValues(matches); db.Entry(matchInDB).State = EntityState.Modified; db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!MatchesExists(id)) { return(NotFound()); } else { throw; } } HubSend(matches); return(StatusCode(StatusCodes.Status204NoContent)); }
public IQueryable <PlayersOfMatches> GetPlayersOfMatchByTeam([FromQuery] string hometeamname, [FromQuery] string awayteamname, [FromQuery] int competitionid, [FromQuery] int selectedmatchid) { hometeamname = hometeamname != null?hometeamname.Trim() : string.Empty; awayteamname = awayteamname != null?awayteamname.Trim() : string.Empty; Matches selectedMatch = _dystirDBContext.Matches?.FirstOrDefault(x => x.MatchID == selectedmatchid); if (selectedMatch == null) { return(Enumerable.Empty <PlayersOfMatches>().AsQueryable()); } selectedMatch.MatchTypeName = selectedMatch.MatchTypeName != null?selectedMatch.MatchTypeName.Trim() : string.Empty; var lastmatches = _dystirDBContext.Matches?.Where(x => x.MatchTypeName.ToLower() == selectedMatch.MatchTypeName.ToLower() && (x.StatusID == 12 || x.StatusID == 13) && (x.HomeTeam.ToLower() == hometeamname.ToLower() || x.AwayTeam.ToLower() == hometeamname.ToLower() || x.HomeTeam.ToLower() == awayteamname.ToLower() || x.AwayTeam.ToLower() == awayteamname.ToLower())).OrderByDescending(x => x.Time); int?hometeamLastMatchID = lastmatches?.FirstOrDefault(x => x.HomeTeam.ToLower() == hometeamname.ToLower() || x.AwayTeam.ToLower() == hometeamname.ToLower())?.MatchID; int?awayteamLastMatchID = lastmatches?.FirstOrDefault(x => x.HomeTeam.ToLower() == awayteamname.ToLower() || x.AwayTeam.ToLower() == awayteamname.ToLower())?.MatchID; var playersByMatchID = GetPlayersOfMatchesByMatchID(selectedmatchid).ToList(); var homePlayersFromLastMatch = hometeamLastMatchID != null? GetPlayersOfMatchesByMatchID((int)hometeamLastMatchID).Where(x => x.TeamName == hometeamname).ToList() : new List <PlayersOfMatches>(); var awayPlayersFromLastMatch = awayteamLastMatchID != null? GetPlayersOfMatchesByMatchID((int)awayteamLastMatchID).Where(x => x.TeamName == awayteamname).ToList() : new List <PlayersOfMatches>(); homePlayersFromLastMatch.AddRange(awayPlayersFromLastMatch); var playersFromLastMatch = homePlayersFromLastMatch?.Where(x => !playersByMatchID.Any(p => p.PlayerId == x.PlayerId)); foreach (PlayersOfMatches player in playersFromLastMatch ?? new List <PlayersOfMatches>()) { PlayersOfMatches newPlayerOfMatch = new PlayersOfMatches() { MatchId = selectedmatchid, FirstName = player.FirstName, Lastname = player.Lastname, TeamName = player.TeamName, TeamId = player.TeamId, Number = player.Number, PlayerId = player.PlayerId, Position = player.Position, Captain = player.Captain, MatchTypeName = player.MatchTypeName, MatchTypeId = player.MatchTypeId, PlayingStatus = 0, Goal = 0, OwnGoal = 0, SubIn = -1, SubOut = -1, RedCard = 0, YellowCard = 0 }; if (newPlayerOfMatch.PlayerId != null) { _dystirDBContext.PlayersOfMatches.Add(newPlayerOfMatch); } } try { _dystirDBContext.SaveChanges(); } catch {} var allPlayersList = GetPlayersOfMatchesByMatchID(selectedmatchid)?.ToList(); var playersListByTeams = _dystirDBContext.Players? .Where(x => x.Team.ToLower() == hometeamname.ToLower() || x.Team.ToLower() == awayteamname.ToLower()).ToList(); foreach (Players player in playersListByTeams ?? new List <Players>()) { PlayersOfMatches playerOfMatches = new PlayersOfMatches() { FirstName = player.FirstName, Lastname = player.LastName, PlayingStatus = 3, PlayerId = player.PlayerId, MatchId = selectedmatchid, MatchTypeId = competitionid, TeamId = player.TeamId, TeamName = player.Team }; if (playerOfMatches.PlayerId != null && !allPlayersList.Any(pm => pm.PlayerId == playerOfMatches.PlayerId)) { allPlayersList.Add(playerOfMatches); } else { string name = player.FirstName + " " + player.LastName; } } return(SortedPlayersOfMatchList(allPlayersList.AsQueryable())); }