public ActionResult PlacesAtMatch(int matchId) { var match = _matchRepo.Get(matchId); var stadium = _stadiumRepo.Get(match.StadiumId); var model = new PlacesAtMatchViewModel() { Match = match, Sectors = stadium.Sectors.ToDictionary(x => x.Number), PlacesBySector = match.PlaceAtMatches.GroupBy(x => x.SectorNumber).ToDictionary(x => x.Key, x => x.ToList()), ReservedPlaces = match.PlaceAtMatches.Where(p => _reservationService.PlaceIsOccupied(p)).Select(p => p.Id).ToList(), Stadium = stadium, }; return(View(model)); }
public List <PriceComponent> CalculatePrice(PlaceAtMatch placeInRun) { var components = new List <PriceComponent>(); var match = _matchRepository.Get(placeInRun.Match.Id); var stadium = _stadiumRepository.Get(match.StadiumId); var place = stadium.Sectors .Select(s => s.Places.SingleOrDefault(pl => pl.Number == placeInRun.Number && s.Number == placeInRun.SectorNumber)) .SingleOrDefault(x => x != null); var placeComponent = new PriceComponent() { Name = "Main price" }; placeComponent.Value = place.Sector.DefaultPrice * place.PriceMultiplier; components.Add(placeComponent); if (placeComponent.Value > 30) { var cashDeskComponent = new PriceComponent() { Name = "Cash desk service tax", Value = placeComponent.Value * 0.2m }; components.Add(cashDeskComponent); } return(components); }
public Match CreateMatch(int stadiumId, DateTime dateTime, string header) { if (GetAvailableTimesForNewMatch(stadiumId, dateTime).Count < 1) { throw new InvalidOperationException(String.Format("Train {0} is occupied at {1}. Run can not be created", stadiumId, dateTime)); } var stadium = _stadiumRepo.Get(stadiumId); var match = new Match() { StadiumId = stadium.Id, DateTime = dateTime, Header = header, PlaceAtMatches = new List <PlaceAtMatch>() }; foreach (var sector in stadium.Sectors) { foreach (var place in sector.Places) { var newPlaceAtMatch = new PlaceAtMatch() { Number = place.Number, SectorNumber = sector.Number, Match = match }; match.PlaceAtMatches.Add(newPlaceAtMatch); } ; } ; _matchRepo.CreateMatch(match); return(match); }