public List <PriceComponent> CalculatePrice(TicketPriceParametersDTO priceParametersDTO)
        {
            var components = new List <PriceComponent>();

            var run   = _runRepository.GetRunDetails(priceParametersDTO.PlaceInRun.RunId);
            var train = _trainRepository.GetTrainDetails(run.TrainId);
            var place =
                train.Carriages
                .Select(car => car.Places.SingleOrDefault(pl =>
                                                          pl.Number == priceParametersDTO.PlaceInRun.Number &&
                                                          car.Number == priceParametersDTO.PlaceInRun.CarriageNumber))
                .SingleOrDefault(x => x != null);

            var placeComponent = new PriceComponent()
            {
                Name = "Main price"
            };

            placeComponent.Value = place.Carriage.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);
        }
Пример #2
0
        public List <PriceComponent> CalculatePrice(TicketPriceParametersDTO priceParametersDTO)
        {
            var components = new List <PriceComponent>();

            foreach (var strategy in _strategies)
            {
                components.AddRange(strategy.CalculatePrice(priceParametersDTO));
            }
            return(components);
        }
Пример #3
0
        public List <PriceComponent> CalculatePrice(TicketPriceParametersDTO priceParametersDTO)
        {
            var components = new List <PriceComponent>();

            var run          = _runRepository.GetRunDetails(priceParametersDTO.PlaceInRun.RunId);
            var train        = _trainRepository.GetTrainDetails(run.TrainId);
            var carriagetype = train.Carriages.FirstOrDefault(x => x.Number == priceParametersDTO.PlaceInRun.CarriageNumber).Type;

            if (priceParametersDTO.Drink == true)
            {
                components.Add(new PriceComponent {
                    Name = "Drink price", Value = 5, Ticket = priceParametersDTO.Ticket, TicketId = priceParametersDTO.Ticket.Id
                });
            }
            if (priceParametersDTO.Bed == true && carriagetype != CarriageType.Sedentary)
            {
                components.Add(new PriceComponent {
                    Name = "Bed price", Value = 15, Ticket = priceParametersDTO.Ticket, TicketId = priceParametersDTO.Ticket.Id
                });
            }

            return(components);
        }