Skip to content
This repository has been archived by the owner on Apr 8, 2023. It is now read-only.

Commit

Permalink
Add states for unsigned -> rostered (#109)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminsampica authored Jul 6, 2022
1 parent 665fae7 commit ca54264
Show file tree
Hide file tree
Showing 17 changed files with 735 additions and 76 deletions.
2 changes: 1 addition & 1 deletion src/Client/Features/FreeAgents/List.razor
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</MudTd>
<MudTd DataLabel="Highest Bid">
<span>
@context.HighestBid.ToString("C")
@context.HighestBid.ToString("C0")
@if (context.CurrentUserIsHighestBidder)
{
<MudChip Color=Color.Success Size=Size.Small>You!</MudChip>
Expand Down
1 change: 0 additions & 1 deletion src/Server/Features/Error.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
</div>
</body>

</html>
8 changes: 4 additions & 4 deletions src/Server/Features/Teams/Detail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public async Task<TeamDetailResult> Handle(DetailQuery request, CancellationToke
.SingleAsync(cancellationToken);

var rosteredPlayersQuery = _dbContext.Players
.Where(p => p.TeamId == request.TeamId)
.WhereIsRostered();
.Where(p => p.TeamId == request.TeamId
&& p.State == PlayerState.Rostered);
var rosteredPlayers = await rosteredPlayersQuery
.ProjectTo<PlayerItem>(_mapper.ConfigurationProvider)
.ToListAsync(cancellationToken);
Expand All @@ -61,8 +61,8 @@ public async Task<TeamDetailResult> Handle(DetailQuery request, CancellationToke
var rosteredPlayersContractValue = await rosteredPlayersQuery.SumAsync(rp => rp.ContractValue, cancellationToken);

var unrosteredPlayersQuery = _dbContext.Players
.Where(p => p.TeamId == request.TeamId)
.WhereIsUnrostered();
.Where(p => p.TeamId == request.TeamId
&& p.State == PlayerState.Unrostered);
var unrosteredPlayers = await unrosteredPlayersQuery
.ProjectTo<PlayerItem>(_mapper.ConfigurationProvider)
.ToListAsync(cancellationToken);
Expand Down
8 changes: 4 additions & 4 deletions src/Server/Features/Teams/List.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ await Parallel.ForEachAsync(teams, async (team, cancellationToken) =>
using var dbContext = await _dbContext.CreateDbContextAsync(cancellationToken);

var rosteredPlayersQuery = dbContext.Players
.Where(p => p.TeamId == team.Id)
.WhereIsRostered();
.Where(p => p.TeamId == team.Id
&& p.State == PlayerState.Rostered);
var rosteredPlayerCount = await rosteredPlayersQuery.CountAsync(cancellationToken);
team.RosteredPlayerCount = rosteredPlayerCount.ToString();

var rosteredPlayersContractValue = await rosteredPlayersQuery.SumAsync(rp => rp.ContractValue, cancellationToken);

var unrosteredPlayersQuery = dbContext.Players
.Where(p => p.TeamId == team.Id)
.WhereIsUnrostered();
.Where(p => p.TeamId == team.Id
&& p.State == PlayerState.Unrostered);
var unrosteredPlayerCount = await unrosteredPlayersQuery.CountAsync(cancellationToken);
team.UnrosteredPlayerCount = unrosteredPlayerCount.ToString();

Expand Down
2 changes: 1 addition & 1 deletion src/Server/Features/Teams/SignPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public async Task<int> Handle(SignPlayerCommand request, CancellationToken cance
var position = Position.FromName(player.Position);
var contractValue = position.GetContractValue(request.YearContractExpires, player.ContractValue);

player.SetToRostered(request.YearContractExpires, contractValue);
player.SignForCurrentTeam(request.YearContractExpires, contractValue);

await _dbContext.SaveChangesAsync(cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using DynamoLeagueBlazor.Server.Models;
using Microsoft.EntityFrameworkCore.Migrations;
using System.Text;

#nullable disable

Expand All @@ -17,13 +16,12 @@ protected override void Up(MigrationBuilder migrationBuilder)
nullable: true);

// Convert Free Agents to use state.
var sql = new StringBuilder();
sql.AppendLine("UPDATE Players")
.AppendLine("SET State = 0")
.AppendLine($"WHERE {nameof(Player.EndOfFreeAgency)} >= getdate()")
.AppendLine($"AND {nameof(Player.YearContractExpires)} < YEAR(getdate())");
var sql = $@"UPDATE Players
SET State = 1
WHERE {nameof(Player.EndOfFreeAgency)} >= getdate()
AND {nameof(Player.YearContractExpires)} < YEAR(getdate())";

migrationBuilder.Sql(sql.ToString());
migrationBuilder.Sql(sql);
}

protected override void Down(MigrationBuilder migrationBuilder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using DynamoLeagueBlazor.Server.Models;
using Microsoft.EntityFrameworkCore.Migrations;
using System.Text;

#nullable disable

Expand All @@ -11,22 +10,20 @@ public partial class AddPlayerStateOfferMatchingToUnsigned : Migration
protected override void Up(MigrationBuilder migrationBuilder)
{
// Convert Offer Matches to use state.
var sql = new StringBuilder();
sql.AppendLine("UPDATE Players")
.AppendLine("SET State = 1")
.AppendLine($"WHERE DATEADD(day, 3, {nameof(Player.EndOfFreeAgency)}) <= getdate()");
var sql = $@"UPDATE Players
SET State = 1
WHERE DATEADD(day, 3, {nameof(Player.EndOfFreeAgency)}) <= getdate()";

migrationBuilder.Sql(sql.ToString());
migrationBuilder.Sql(sql);
}

protected override void Down(MigrationBuilder migrationBuilder)
{
var sql = new StringBuilder();
sql.AppendLine("UPDATE Players")
.AppendLine("SET State = NULL")
.AppendLine($"WHERE STATE = 1");
var sql = @"UPDATE Players
SET State = NULL
WHERE STATE = 1";

migrationBuilder.Sql(sql.ToString());
migrationBuilder.Sql(sql);
}
}
}
Loading

0 comments on commit ca54264

Please sign in to comment.