Ejemplo n.º 1
0
        public string UpdateBet(string id, string value)
        {
            var trimedValue = value.Replace(" ", "");

            var game = this._gameService.GetGame(Guid.Parse(id));
            var bet = this._gameService.FindBet(Guid.Parse(id), User.Identity.Name);
            if (bet == null)
                bet = new Bet { Game = game };

            //TODO: popup ze nie mozna jeszcze zrobic fi
            if (!this._gameService.CanBetGame(game.GameStartDate))
                return (bet.Id == Guid.Empty) ? "?:?" : bet.Result.HomeGoals + ":" + bet.Result.GuestGoals;

            var splitedString = trimedValue.Split(':');
            int homeGoals;
            int guestGoals;
            //złe dane
            if (!int.TryParse(splitedString[0], out homeGoals) || !int.TryParse(splitedString[1], out guestGoals))
            {
                return (bet.Id == Guid.Empty) ? "?:?" : bet.Result.HomeGoals + ":" + bet.Result.GuestGoals;
            }

            //validacja
            if (homeGoals >= 100 || guestGoals >= 100 || homeGoals < 0 || guestGoals < 0)
            {
                return (bet.Id == Guid.Empty) ? "?:?" : bet.Result.HomeGoals + ":" + bet.Result.GuestGoals;
            }

            //create
            if (bet.Id == Guid.Empty)
            {
                bet.UserName = User.Identity.Name;
                bet.Result = new Result{HomeGoals = homeGoals, GuestGoals = guestGoals};
                this._gameService.SaveBet(bet);
            }
            //edit
            else
            {
                bet.Result.HomeGoals = homeGoals;
                bet.Result.GuestGoals = guestGoals;
                this._gameService.UpdateBet(bet);
            }

            return homeGoals + ":" + guestGoals;
        }
Ejemplo n.º 2
0
        public void Setup()
        {
            this._scorer = new Scorer();
            this._game = new Game
                        {
                            Result = new Result { HomeGoals = 1, GuestGoals = 1 },
                            HomeTeam = new Team(),
                            GuestTeam = new Team(),
                            GameStartDate = DateTime.Now,
                        };

            this._bet = new Bet { Game = _game };
        }