예제 #1
0
 public MakeBetViewModel(long battleId, string startDate, string endDate, int budget, int betLimit, IEnumerable<SelectListItem> teams, MakeBetFormViewModel makeBetViewModel)
     : base(battleId, startDate, endDate, budget, betLimit)
 {
     BattleId = battleId;
     Teams = teams;
     MakeBetForm = makeBetViewModel;
 }
예제 #2
0
        public MakeBetViewModel MakeBet(long battleId, long userId, MakeBetFormViewModel makeBetFormViewModel)
        {
            var battle = _repositoryOfBattle.Get(EntitySpecifications.IdIsEqualTo<Battle>(battleId)).Single();

            var teams = _repositoryOfTeam.Get(TeamSpecifications.UserIsMember(userId)).ToList();
            var personalTeam = teams.Where(t => t.IsPersonal).Single();
            teams.Remove(personalTeam);
            teams.Insert(0, personalTeam);
            var teamsSelectListItems = teams.Select(
                t =>
                {
                    string title;
                    if (t.IsPersonal)
                        title = Bets.MePersonally;
                    else
                        title = String.Format("{0} {1}", Bets.OfTeam, t.Title);
                    var selectListItem = new SelectListItem() { Value = t.Id.ToString(), Text = title };
                    return selectListItem;
                }).
                ToList();
            if (makeBetFormViewModel.TeamId == 0 && teamsSelectListItems.Count == 2)
                makeBetFormViewModel.TeamId = teams[1].Id; //select non-personal team by default

            var makeBetViewModel = new MakeBetViewModel(battleId, battle.StartDate.ToShortDateString(), battle.EndDate.ToShortDateString(), battle.Budget, battle.BetLimit, teamsSelectListItems, makeBetFormViewModel);

            return makeBetViewModel;
        }
예제 #3
0
        public virtual ActionResult MakeBet(long battleId, MakeBetFormViewModel makeBetForm)
        {
            if (!ModelState.IsValid)
                return View(_betsViewService.MakeBet(battleId, CurrentUser.UserId, makeBetForm));

            _battlesService.MakeBet(battleId, makeBetForm.TeamId, CurrentUser.UserId, makeBetForm.Title, makeBetForm.Amount.Value, makeBetForm.Coefficient.Value, makeBetForm.Url, makeBetForm.IsPrivate);

            return RedirectToAction(MVC.NotAdmin.Battles.GetBattle(battleId));
        }