Beispiel #1
0
        public Ticket CreateTicket(int reservationId, string fName, string lName)
        {
            var res = _resRepo.Get(reservationId);

            if (res.TicketId != null)
            {
                throw new InvalidOperationException("ticket has been already issued to this reservation, unable to create another one");
            }

            var placeInRun = _runRepository.GetPlaceInRun(res.PlaceInRunId);

            var newTicket = new Ticket()
            {
                ReservationId   = res.Id,
                CreatedDate     = DateTime.Now,
                FirstName       = fName,
                LastName        = lName,
                Status          = TicketStatusEnum.Active,
                PriceComponents = new List <PriceComponent>()
            };

            newTicket.PriceComponents = _priceStr.CalculatePrice(placeInRun);

            res.TicketId = newTicket.Id;
            _resRepo.Update(res);

            _tickRepo.Create(newTicket);
            return(newTicket);
        }
        public ActionResult ReservePhone(int phoneId, int quantity)
        {
            _reservationService.ReservationChecker();
            var phone = _phoneRepository.GetPhone(phoneId);

            if (phone.Amount < quantity || quantity <= 0)
            {
                return(RedirectToAction("Eroor"));
            }

            var parametrs = new PriceStrategyParametersDTO();

            parametrs.PhoneId  = phoneId;
            parametrs.Quantity = quantity;

            var reservation = _reservationService.Reserve(phoneId, quantity);

            var model = new ReservationViewModel()
            {
                Reservation = reservation,
                Phone       = phone,
                OrderItem   = _priceCalculationStrategy.CalculatePrice(parametrs),
                Quantity    = quantity
            };

            return(View(model));
        }
        public List <PriceComponent> CalculatePrice(PlaceInRun placeInRun)
        {
            var components = new List <PriceComponent>();

            components.AddRange(_strat1.CalculatePrice(placeInRun));
            components.AddRange(_strat2.CalculatePrice(placeInRun));

            return(components);
        }
        public ActionResult ReservePlace(int placeId)
        {
            var place = _runRepo.GetPlaceInRun(placeId);

            var reservation = _resServ.Reserve(place);
            var model       = new ReservationViewModel()
            {
                Reservation     = reservation,
                PlaceInRun      = place,
                PriceComponents = _priceCalculationStrategy.CalculatePrice(place),
                Date            = place.Run.Date,
                Train           = _trainRepo.GetTrainDetails(place.Run.TrainId),
            };

            return(View(model));
        }
Beispiel #5
0
        public void BuyGame(Game game, User usr)
        {
            usr.Money -= (float)_priceCalculationStrategy.CalculatePrice(game);
            LibraryItem li = new LibraryItem();

            li.GameId = game.Id;
            li.User   = usr;
            li.UserId = usr.Id;
            if (usr.UserLibrary == null)
            {
                usr.UserLibrary = new List <LibraryItem>();
            }

            usr.UserLibrary.Add(li);
            _UserRepo.UpdateUser(usr);
        }
        public ActionResult ReservePlace(int placeId)
        {
            var place = _matchRepo.GetPlaceAtMatch(placeId);

            var reservation = _reservationService.Reserve(place);
            var model       = new ReservationViewModel()
            {
                Reservation     = reservation,
                PlaceInRun      = place,
                PriceComponents = _priceCalculationStrategy.CalculatePrice(place),
                DateTime        = place.Match.DateTime,
                Stadium         = _stadiumRepo.Get(place.Match.StadiumId),
            };

            return(View(model));
        }
Beispiel #7
0
        public List <PriceComponent> CalculatePrice(TicketParametersDTO parametrs)
        {
            var components = new List <PriceComponent>();

            var            defaultPrice = _priceCalculationStrategy.CalculatePrice(parametrs);
            PriceComponent mainPrice    = defaultPrice.Find(p => p.Name == "Main price");

            if (parametrs.Code != null)
            {
                components.Add(new PriceComponent
                {
                    Name     = "Code markup price",
                    Ticket   = parametrs.Ticket,
                    TicketId = parametrs.Ticket.Id,
                    Value    = _bookingAgencies.GetMarkup(parametrs.Code)
                });
            }

            return(components);
        }
        public List <PriceComponent> CalculatePrice(PlaceInRun placeInRun)
        {
            var train           = _trainRepository.GetTrainDetails(placeInRun.Run.TrainId);
            var priceComponents = new List <PriceComponent>();

            priceComponents.AddRange(_strategy.CalculatePrice(placeInRun));
            var sum = 0m;

            foreach (var p in priceComponents)
            {
                sum += p.Value;
            }
            var AgencyComponent = new PriceComponent {
                Name = "AgencyMargin", Value = train.CompanyMargin.Margin * sum
            };

            priceComponents.Add(AgencyComponent);
            return(priceComponents
                   );
        }
Beispiel #9
0
        public List <PriceComponent> CalculatePrice(PlaceInRun placeInRun)
        {
            var priceComponents = new List <PriceComponent>();

            priceComponents.AddRange(_strategy.CalculatePrice(placeInRun));
            var teaComponent = new PriceComponent {
                Name = "Tea price", Value = PriceList.TEA * _teaCount
            };

            priceComponents.Add(teaComponent);
            var coffeeComponent = new PriceComponent {
                Name = "Coffee price", Value = PriceList.COFFEE * _coffeeCount
            };

            priceComponents.Add(coffeeComponent);
            var cookiesComponent = new PriceComponent {
                Name = "Cookies price", Value = PriceList.COOKIES * _cookiesCount
            };

            priceComponents.Add(cookiesComponent);
            return(priceComponents);
        }
        public List <PriceComponent> CalculatePrice(PlaceInRun placeInRun)
        {
            var components = new List <PriceComponent>();

            components.AddRange(_priceCalculationStrategy.CalculatePrice(placeInRun));

            if (IsHoliday(placeInRun.Run.Date))
            {
                var sum = 0m;

                foreach (var component in components)
                {
                    sum += component.Value;
                }

                components.Add(new PriceComponent {
                    Name = "Holidays fee", Value = sum * Constants.HolidayPriceMultiplier
                });
            }

            return(components);
        }
Beispiel #11
0
        public Order CreateOrder(OrderParametersDTO parametersDTO)
        {
            var res = _resRepo.Get(parametersDTO.ReservationId);

            if (res.OrderId != null)
            {
                throw new InvalidOperationException("Phone has been already issued to this reservation, unable to create another one");
            }

            var phone = _phoneRepository.GetPhone(res.ReservedItem.PhoneId);

            var newOrder = new Order()
            {
                ReservationId = res.Id,
                OrderDate     = DateTime.Now,
                Name          = parametersDTO.Name,
                Address       = parametersDTO.Address,
                Email         = parametersDTO.Email,
                City          = parametersDTO.City,
                Status        = OrderStatusEnum.Active,
                OrderItems    = new List <OrderItem>()
            };

            var priceParametrs = new PriceStrategyParametersDTO();

            priceParametrs.PhoneId  = phone.Id;
            priceParametrs.Quantity = parametersDTO.Quantity;

            newOrder.OrderItems = _priceStr.CalculatePrice(priceParametrs);

            res.OrderId = newOrder.Id;
            _resRepo.Update(res);

            _orderRepository.Create(newOrder);
            return(newOrder);
        }
        public Ticket CreateTicket(int reservationId, string fName, string lName)
        {
            var res = _resRepo.Get(reservationId);

            if (res.TicketId != null)
            {
                throw new InvalidOperationException("ticket has been already issued to this reservation, unable to create another one");
            }

            var placeInRun = _matchRepo.GetPlaceAtMatch(res.PlaceAtMatchId);

            var newTicket = new Ticket()
            {
                ReservationId   = res.Id,
                FirstName       = fName,
                LastName        = lName,
                PriceComponents = new List <PriceComponent>()
            };

            newTicket.PriceComponents = _priceCalculationStrategy.CalculatePrice(placeInRun);

            _tickRepo.CreateTicket(newTicket);
            return(newTicket);
        }
Beispiel #13
0
        public List <PriceComponent> CalculatePrice(PriceCalculationParametersDTO PriceCalculationParameters)
        {
            var components = new List <PriceComponent>();

            components.AddRange(_priceCalculationStrategy.CalculatePrice(PriceCalculationParameters));
            if (PriceCalculationParameters.IsTea == true)
            {
                var cashForTea = new PriceComponent()
                {
                    Name  = "Pay for tea",
                    Value = 7,
                };
                components.Add(cashForTea);
            }

            if (PriceCalculationParameters.IsCoffee == true)
            {
                var cashForCoffee = new PriceComponent()
                {
                    Name  = "Pay for Coffee",
                    Value = 8
                };
                components.Add(cashForCoffee);
            }

            if (PriceCalculationParameters.IsBed == true)
            {
                var cashForBed = new PriceComponent()
                {
                    Name  = "Pay for Bed",
                    Value = 15
                };
                components.Add(cashForBed);
            }
            return(components);
        }