public ActionResult AddHorse(int id)
        {
            RaceDetail rd = new RaceDetail();
            LeagueRace leagueRace = this.UserLeague.League.GetLeagueRace(id);
            rd.LeagueRace = leagueRace;

            this.ViewData.Model = rd;

            return View();
        }
        public virtual void AddUserPick(LeagueRace leagueRace, RaceDetail raceDetail, BetTypes betType)
        {
            var userPick = GetPicksForARace(leagueRace).Where(x => x.BetType == betType).FirstOrDefault();

            if (userPick != null && userPick.RaceDetail != raceDetail)
            {
                this.UserRaceDetails.Remove(userPick);
            }
            else if(userPick != null && userPick.RaceDetail == raceDetail)
            {
                return;
            }
            createAndAddUserRace(betType, raceDetail);
        }
 public static string FormatHorseNameForDisplay(RaceDetail rd)
 {
     return FormatHorseNameForDisplay(rd.PostPosition, rd.Horse.Name);
 }
        private void createAndAddUserRace(BetTypes betType, RaceDetail raceDetail)
        {
            UserRaceDetail urd = new UserRaceDetail();

            urd.BetType = betType;
            urd.RaceDetail = raceDetail;
            urd.UserLeague = this;
            urd.UpdateDate = System.DateTime.Now;

            this.UserRaceDetails.Add(urd);
        }
        public virtual RaceDetailPayout GetFinishPosition(RaceDetail raceDetail)
        {
            if (Win.RaceDetail == raceDetail)
                return Win;

            if (Place.RaceDetail == raceDetail)
                return Place;

            if (Show.RaceDetail == raceDetail)
                return Show;

            return null;
        }
        public ActionResult AddHorse(int id, FormCollection collection)
        {
            #region Validation
            string horseName = collection["Horse"];
            if (horseName == null)
            {
                ModelState.AddModelError("Horse", "The horse name can not be blank");
                return View();
            }

            string postPosition = collection["PostPosition"];
            int post;
            if (!Int32.TryParse(postPosition, out post))
            {
                ModelState.AddModelError("PostPosition", "The post position can not be blank");
                return View();
            }
            #endregion

            try
            {

                Horse horse = this.horseRepository.GetHorseByName(horseName);
                if (horse == null)
                {
                    //Horse didn't exist add it
                    horse = new Horse();
                    horse.Name = horseName;

                    horse = this.horseRepository.SaveOrUpdate(horse);
                }

                LeagueRace leagueRace = this.UserLeague.League.GetLeagueRace(id);

                //Add the new race detail
                RaceDetail detail = new RaceDetail();
                detail.Horse = horse;
                detail.LeagueRace = leagueRace;
                detail.PostPosition = post;
                raceDetailRepository.SaveOrUpdate(detail);

                //leagueRace.RaceDetails.Add(detail);
               // leagueRaceRepository.SaveOrUpdate(leagueRace);

                return RedirectToAction("ViewLeagueRace", new { id = id });
            }
            catch
            {
                this.leagueRaceRepository.DbContext.RollbackTransaction();
                throw;
            }
        }