From 2068a310d31a3e422049c05da3f233ce3f3acdcc Mon Sep 17 00:00:00 2001 From: "roi.ezra" Date: Thu, 12 Sep 2024 18:25:05 +0300 Subject: [PATCH 1/2] some client flags fixes --- Mundialito/Client/src/Games/Game.html | 17 +++++++++-------- Mundialito/Models/BetsModels.cs | 9 +++++++++ Mundialito/wwwroot/App/Games/Game.html | 17 +++++++++-------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Mundialito/Client/src/Games/Game.html b/Mundialito/Client/src/Games/Game.html index e873e32..5d5fdf5 100644 --- a/Mundialito/Client/src/Games/Game.html +++ b/Mundialito/Client/src/Games/Game.html @@ -64,7 +64,7 @@
+ class="form-control" placeholder="{{game.HomeTeam.Name}} Score" required min="0">
-
+
You haven't placed a bet on this game and it is already closed for betting
-
+
@@ -254,7 +254,7 @@
@@ -265,7 +265,7 @@
@@ -522,17 +522,18 @@
diff --git a/Mundialito/Models/BetsModels.cs b/Mundialito/Models/BetsModels.cs index a81156e..ff30ec8 100644 --- a/Mundialito/Models/BetsModels.cs +++ b/Mundialito/Models/BetsModels.cs @@ -235,7 +235,10 @@ public BetGameTeam(Team team) TeamId = team.TeamId; Name = team.Name; ShortName = team.ShortName; + Logo = team.Logo; + Flag = team.Flag; } + [JsonPropertyName("TeamId")] public int TeamId { get; set; } @@ -245,4 +248,10 @@ public BetGameTeam(Team team) [JsonPropertyName("ShortName")] public string ShortName { get; set; } + [JsonPropertyName("Flag")] + public string Flag { get; set; } + + [JsonPropertyName("Logo")] + public string Logo { get; set; } + } diff --git a/Mundialito/wwwroot/App/Games/Game.html b/Mundialito/wwwroot/App/Games/Game.html index 6636352..0cb63ea 100644 --- a/Mundialito/wwwroot/App/Games/Game.html +++ b/Mundialito/wwwroot/App/Games/Game.html @@ -64,7 +64,7 @@
+ class="form-control" placeholder="{{game.HomeTeam.Name}} Score" required min="0">
-
+
You haven't placed a bet on this game and it is already closed for betting
-
+
@@ -254,7 +254,7 @@
@@ -265,7 +265,7 @@
@@ -522,17 +522,18 @@
From 22bd2475c0676dea77abb43bcd72ecdfad45f45e Mon Sep 17 00:00:00 2001 From: "roi.ezra" Date: Thu, 12 Sep 2024 18:52:56 +0300 Subject: [PATCH 2/2] fixed general bets --- .../Controllers/GeneralBetsController.cs | 35 +++++++++++++------ Mundialito/Models/GeneralBetsModels.cs | 16 +++++++-- 2 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Mundialito/Controllers/GeneralBetsController.cs b/Mundialito/Controllers/GeneralBetsController.cs index 4eadd6d..7995fb0 100644 --- a/Mundialito/Controllers/GeneralBetsController.cs +++ b/Mundialito/Controllers/GeneralBetsController.cs @@ -4,6 +4,8 @@ using Mundialito.DAL.Accounts; using Mundialito.DAL.ActionLogs; using Mundialito.DAL.GeneralBets; +using Mundialito.DAL.Players; +using Mundialito.DAL.Teams; using Mundialito.Logic; using Mundialito.Models; @@ -21,16 +23,20 @@ public class GeneralBetsController : ControllerBase private readonly IHttpContextAccessor httpContextAccessor; private readonly TournamentTimesUtils tournamentTimesUtils; private readonly UserManager userManager; + private readonly ITeamsRepository teamsRepository; + private readonly IPlayersRepository playersRepository; private readonly ILogger logger; - public GeneralBetsController(ILogger logger, IGeneralBetsRepository generalBetsRepository, IDateTimeProvider dateTimeProvider, IActionLogsRepository actionLogsRepository, IHttpContextAccessor httpContextAccessor, TournamentTimesUtils tournamentTimesUtils, UserManager userManager) + public GeneralBetsController(ILogger logger, IGeneralBetsRepository generalBetsRepository, IDateTimeProvider dateTimeProvider, IActionLogsRepository actionLogsRepository, IHttpContextAccessor httpContextAccessor, TournamentTimesUtils tournamentTimesUtils, UserManager userManager, ITeamsRepository teamsRepository, IPlayersRepository playersRepository) { - this.httpContextAccessor = httpContextAccessor; - this.dateTimeProvider = dateTimeProvider; this.generalBetsRepository = generalBetsRepository; + this.dateTimeProvider = dateTimeProvider; this.actionLogsRepository = actionLogsRepository; + this.httpContextAccessor = httpContextAccessor; this.tournamentTimesUtils = tournamentTimesUtils; this.userManager = userManager; + this.teamsRepository = teamsRepository; + this.playersRepository = playersRepository; this.logger = logger; } @@ -81,6 +87,8 @@ public ActionResult GetGeneralBetById(int id) [Authorize(Roles = "Active,Admin")] public async Task> PostBet(NewGeneralBetModel newBet) { + if (generalBetsRepository.IsGeneralBetExists(httpContextAccessor.HttpContext?.User.Identity.Name)) + return BadRequest(new ErrorMessage { Message = "You have already submitted your general bet, only update is permitted"}); var validate = Validate(); if (!string.IsNullOrEmpty(validate)) { @@ -90,11 +98,23 @@ public async Task> PostBet(NewGeneralBetModel n var user = await userManager.FindByNameAsync(httpContextAccessor.HttpContext?.User.Identity.Name); if (user == null) return Unauthorized(); + var winningTeam = teamsRepository.GetTeam(newBet.WinningTeam.TeamId); + if (winningTeam == null) + { + AddLog(ActionType.ERROR, string.Format("Team with id '{0}' dosen't exits", newBet.WinningTeam.TeamId)); + return NotFound(new ErrorMessage { Message = string.Format("Team with id '{0}' dosen't exits", newBet.WinningTeam.TeamId)}); + } + var goldenBootPlayer = playersRepository.GetPlayer(newBet.GoldenBootPlayer.PlayerId); + if (goldenBootPlayer == null) + { + AddLog(ActionType.ERROR, string.Format("Player with id '{0}' dosen't exits", newBet.GoldenBootPlayer.PlayerId)); + return NotFound(new ErrorMessage { Message = string.Format("Player with id '{0}' dosen't exits", newBet.GoldenBootPlayer.PlayerId)}); + } var generalBet = new GeneralBet { User = user, - WinningTeam = newBet.WinningTeam, - GoldBootPlayer = newBet.GoldenBootPlayer + WinningTeam = winningTeam, + GoldBootPlayer = goldenBootPlayer }; var res = generalBetsRepository.InsertGeneralBet(generalBet); logger.LogInformation("Posting new general bet {} from {}", generalBet, user.UserName); @@ -156,11 +176,6 @@ public IActionResult ResolveGeneralBet(int id, ResolveGeneralBetModel resolvedBe private string Validate() { - if (generalBetsRepository.IsGeneralBetExists(httpContextAccessor.HttpContext?.User.Identity.Name)) - { - AddLog(ActionType.ERROR, "You have already submitted your general bet, only update is permitted"); - return "You have already submitted your general bet, only update is permitted"; - } if (dateTimeProvider.UTCNow > tournamentTimesUtils.GetGeneralBetsCloseTime()) { AddLog(ActionType.ERROR, "General bets are already closed for betting"); diff --git a/Mundialito/Models/GeneralBetsModels.cs b/Mundialito/Models/GeneralBetsModels.cs index e54615b..820100d 100644 --- a/Mundialito/Models/GeneralBetsModels.cs +++ b/Mundialito/Models/GeneralBetsModels.cs @@ -53,15 +53,27 @@ public GeneralBetViewModel(GeneralBet bet, DateTime closeTime) public class NewGeneralBetModel { [JsonPropertyName("WinningTeam")] - public Team WinningTeam { get; set; } + public NewGeneralBetModelWinningTeam WinningTeam { get; set; } [JsonPropertyName("GoldenBootPlayer")] - public Player GoldenBootPlayer { get; set; } + public NewGeneralBetModelGoldenBootPlayer GoldenBootPlayer { get; set; } [JsonPropertyName("GeneralBetId")] public int GeneralBetId { get; set; } } +public class NewGeneralBetModelWinningTeam +{ + [JsonPropertyName("TeamId")] + public int TeamId { get; set; } +} + +public class NewGeneralBetModelGoldenBootPlayer +{ + [JsonPropertyName("PlayerId")] + public int PlayerId { get; set; } +} + public class UpdateGenralBetModel { [JsonPropertyName("WinningTeam")]