public bool ArePricesCorrect(SubmitLineupViewModel model) { return(!(IsPlayerPriceIncorrect(model.PgID, model.PgPrice) || IsPlayerPriceIncorrect(model.SgID, model.SgPrice) || IsPlayerPriceIncorrect(model.SfID, model.SfPrice) || IsPlayerPriceIncorrect(model.PfID, model.PfPrice) || IsPlayerPriceIncorrect(model.CID, model.CPrice))); }
public int GetLineupPrice(SubmitLineupViewModel model) { return(_context.Players.Where(pg => pg.PlayerID == model.PgID).Select(p => p.Price) .Union(_context.Players.Where(sg => sg.PlayerID == model.SgID).Select(p => p.Price)) .Union(_context.Players.Where(sf => sf.PlayerID == model.SfID).Select(p => p.Price)) .Union(_context.Players.Where(pf => pf.PlayerID == model.PfID).Select(p => p.Price)) .Union(_context.Players.Where(c => c.PlayerID == model.CID).Select(p => p.Price)) .Sum()); }
public IActionResult SubmitLineup([FromBody] SubmitLineupViewModel model) { if (_repository.GetLineupPrice(model) > MAX_PRICE) { return(StatusCode(422, "Lineup price exceeds the budget! Lineup was not submitted.")); } if (!_repository.ArePricesCorrect(model)) { return(StatusCode(422, "Wrong player prices! Lineup was not submitted.")); } if (!PlayerSeed.PLAYER_POOL_DATE.Equals(Database.NextGame.NEXT_GAME)) { return(StatusCode(500, "Player pool not updated! Try again in a moment.")); } _service.SubmitLineup(model); return(Ok("Lineup was updated successfully")); }
public async void SubmitLineup(SubmitLineupViewModel model) { if (!_repository.IsUpdating(model.UserID)) { _repository.AddPlayer(model.UserID, "PG", model.PgID); _repository.AddPlayer(model.UserID, "SG", model.SgID); _repository.AddPlayer(model.UserID, "SF", model.SfID); _repository.AddPlayer(model.UserID, "PF", model.PfID); _repository.AddPlayer(model.UserID, "C", model.CID); } else { _repository.UpdatePlayer(model.UserID, "PG", model.PgID); _repository.UpdatePlayer(model.UserID, "SF", model.SgID); _repository.UpdatePlayer(model.UserID, "SF", model.SfID); _repository.UpdatePlayer(model.UserID, "PF", model.PfID); _repository.UpdatePlayer(model.UserID, "C", model.CID); } await _context.SaveChangesAsync(); }