public List <RaceBets> GetRaceDetails()
        {
            var result  = new List <RaceBets>();
            var races   = GetAll();
            var allBets = _betServices.GetAll().ToList();

            foreach (var race in races)
            {
                var raceDetails = new RaceBets {
                    Id = race.Id, Status = race.Status, Name = race.Name
                };
                raceDetails.Bets         = allBets.Where(x => x.RaceId == race.Id).ToList();
                raceDetails.RaceTotalBet = raceDetails.Bets.Sum(x => x.Stake);
                foreach (var horse in race.Horses)
                {
                    var thisRaceHorseBets = raceDetails.Bets.Where(x => x.HorseId == horse.Id).ToList();
                    var horseRace         = new HorseRace
                    {
                        Horse        = horse,
                        RaceId       = race.Id,
                        NumberOfBets = thisRaceHorseBets.Count,
                        TotalBet     = thisRaceHorseBets.Sum(x => x.Stake)
                    };

                    horseRace.OwingOnWin = horseRace.TotalBet * horseRace.Horse.Odds;
                    raceDetails.HorseRaces.Add(horseRace);
                }
                result.Add(raceDetails);
            }
            return(result);
        }
Пример #2
0
 public static RaceBetViewModel ToViewModel(this RaceBets racebet)
 {
     return((racebet == null) ? null
         : new RaceBetViewModel
     {
         Id = racebet.Id,
         Name = racebet.Name,
         Status = racebet.Status,
         RaceTotalBet = racebet.RaceTotalBet,
         HorseRace = racebet.HorseRaces.Select(x => new HorseRaceViewModel {
             HorseId = x.Horse.Id, HorseName = x.Horse.Name, RaceId = x.RaceId, NumberOfBets = x.NumberOfBets, TotalBet = x.TotalBet, OwingOnWin = x.OwingOnWin
         }).ToList()
     });
 }