Exemplo n.º 1
0
        // GET: Unity
        public ActionResult Index()
        {
            string value = priceCalculator.CalculatePrice();

            _logger.LogInfo("Price Added to the calculator");
            return(View());
        }
Exemplo n.º 2
0
        public BuyNow(IPriceCalculator calculator)
        {
            CompositeEvent(() => OrderWasReserved, x => x.OrderWarReservedStatus, OrderFinalized, StockReserved);

            During(Initial,
                   When(PurchaseOrdered).Then((state, domainEvent) =>
            {
                state.AccountId = domainEvent.AccountId;
                state.OrderId   = domainEvent.OrderId;
                state.Quantity  = domainEvent.Quantity;
                state.SkuId     = domainEvent.SkuId;
                state.UserId    = domainEvent.SourceId;
                state.StockId   = domainEvent.StockId;

                Dispatch(new CreateOrderCommand(state.OrderId, state.UserId));
            }).TransitionTo(CreatingOrder));

            During(CreatingOrder,
                   When(OrderCreated).ThenAsync(async(state, e) =>
            {
                var totalPrice =
                    await calculator.CalculatePrice(state.SkuId, state.Quantity);

                Dispatch(new AddItemToOrderCommand(state.OrderId,
                                                   state.SkuId,
                                                   state.Quantity,
                                                   totalPrice));
            }).TransitionTo(AddingOrderItems));

            During(AddingOrderItems,
                   When(ItemAdded)
                   .Then((state, e) => { Dispatch(new ReserveStockCommand(state.StockId, state.UserId, state.Quantity)); })
                   .TransitionTo(Reserving));

            During(Reserving,
                   When(StockReserved).Then((state, domainEvent) =>
            {
                state.ReserveId = domainEvent.ReserveId;
                Dispatch(new CalculateOrderTotalCommand(state.OrderId));
            }),
                   When(OrderFinalized)
                   .Then(
                       (state, domainEvent) => { Dispatch(new PayForOrderCommand(state.AccountId, domainEvent.TotalPrice, state.OrderId)); }),
                   When(OrderWasReserved).TransitionTo(Paying));


            During(Paying,
                   When(OrderPaid, ctx => ctx.Data.ChangeId == ctx.Instance.OrderId)
                   .Then((state, e) => { Dispatch(new TakeReservedStockCommand(state.StockId, state.ReserveId)); })
                   .TransitionTo(TakingStock));

            During(TakingStock,
                   When(ReserveTaken).Then((state, e) =>
            {
                Dispatch(new CompleteOrderCommand(state.OrderId));
                Dispatch(new CompletePendingOrderCommand(state.UserId, state.OrderId));
            }).Finalize());
        }
Exemplo n.º 3
0
 public void CalculatePrices(DateTime now)
 {
     foreach (var cheese in Cheeses)
     {
         DecrementDaysToSell(cheese);
         _priceCalculator.CalculatePrice(cheese, now);
     }
     _printer.Print(Cheeses, now);
 }
        public decimal TotalAmount()
        {
            decimal total = 0m;

            foreach (OrderItem orderItem in OrderItems)
            {
                total += _priceCalculator.CalculatePrice(orderItem);
            }
            return(total);
        }
Exemplo n.º 5
0
        public FilteredList <Product> GetAll(Filter filter)
        {
            _filterValidator.DefaultValidation(filter);
            var filteredList = _productRepo.ReadAll(filter);

            foreach (var product in filteredList.List)
            {
                _productValidator.DefaultValidation(product);
                _priceCalc.CalculatePrice(product);
            }

            return(filteredList);
        }
Exemplo n.º 6
0
 public Order(DateTime date, string paymentType, Package package, string senderName, Address sender, string recipientName, Address recipient, List <Service> services, IPriceCalculator priceCalculator)
 {
     Paid          = false;
     Date          = date;
     PaymentType   = paymentType;
     Status        = "Submitted";
     Package       = package;
     SenderName    = senderName;
     Sender        = sender;
     RecipientName = recipientName;
     Recipient     = recipient;
     Services      = services;
     Price         = priceCalculator.CalculatePrice(this);
 }
Exemplo n.º 7
0
        public async Task <List <Tour> > SearchAsync(TourSearchRequest tourSearchRequest, CancellationToken cancellationToken)
        {
            var tours = _tourRepository.Tours
                        .Where(tourSearchRequest.Criteria)
                        .ApplySorting(tourSearchRequest)
                        .Take(_settings.ToursPackSize)
                        .ToList();

            var personCount = tourSearchRequest.PersonCount.GetValueOrDefault(_settings.DefaultPersonCount);
            await tours.ForEachAsync(Environment.ProcessorCount, x => _priceCalculator.CalculatePrice(x, personCount));

            var random = new Random((int)DateTime.Now.Ticks);
            await Task.Delay(random.Next(3000, 17000), cancellationToken);

            return(tours);
        }
Exemplo n.º 8
0
        public ActionResult CreateStepThree(int?id, int ticketsChildren, int[] seats)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            Showing showing = repo.GetById <Showing>(id);

            if (showing == null)
            {
                return(HttpNotFound());
            }


            double price = 0;

            for (int i = 0; i < seats.Length; i++)
            {
                price += priceCalculator.CalculatePrice(showing, i < ticketsChildren);
            }

            Order order = new Order()
            {
                NumberOfTickets = seats.Length,
                ShowingId       = showing.Id,
                TotalPrice      = price,
            };

            repo.Create <Order>(order);
            repo.Save();

            foreach (int seatId in seats)
            {
                repo.Create <OrderSeat>(new OrderSeat()
                {
                    OrderId = order.Id, SeatId = seatId
                });
            }

            repo.Save();

            ViewBag.ShowingID = id;
            ViewBag.OrderID   = order.Id;

            return(View(order));
        }
Exemplo n.º 9
0
        public ResponseMessage ExecuteOperation(RequestMessage request)
        {
            try
            {
                Order order = _orderRepository.CreateOrder();

                order.OrderItems.AddRange(request.OrderItems);

                foreach (OrderItem item in order.OrderItems)
                {
                    InventoryItem inventoryItem = _inventoryService.GetInventoryItem(item.ItemCode);

                    if (item.Quantity <= inventoryItem.QuantityOnHand)
                    {
                        inventoryItem.QuantityOnHand -= item.Quantity;
                        item.Weight = item.WeightPerUnit * (float)item.Quantity;

                        _priceCalculator.CalculatePrice(item, inventoryItem);

                        item.State = OrderItemState.Filled;
                    }
                    else
                    {
                        item.State = OrderItemState.NotEnoughQuantityOnHand;
                    }
                }

                order.State = order.OrderItems.All(o => o.State == OrderItemState.Filled)
                    ? OrderState.Filled
                    : OrderState.Processing;

                _orderRepository.AddOrder(order);

                // save inventory
                _inventoryService.UpdateInventory();

                // save order
                _orderRepository.UpdateOrders();

                return(_responseMessageFactory.CreateOrderSubmissionResponseMessage(request, order));
            }
            catch (Exception ex)
            {
                _loggerService.WriteLine("Exception during operation SubmitOrder: " + ex, "SubmitOrderError");
                return(_responseMessageFactory.CreateErrorResponseMessage(ex));
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// This method applies the appropriate discounts on each of the scanned item
        /// The discount is applied by invoking the corresponding Discount Type interface
        /// </summary>
        public void CheckOut()
        {
            try
            {
                //Assign product details to each scanned item
                AssignProductDetailsToScannedItems();
                //get unique scanned items
                var uniqueProductIds = scannedItems.Select(i => i.ProductId).Distinct().ToList();

                //Apply the discount for each set of unique scanned items
                uniqueProductIds.ForEach(pId =>
                {
                    //If the scanned item is not present in the Product catalog then price will not be calculated
                    //If the scanned item is not present in the Product catalog then Product id = 0
                    if (pId != 0)
                    {
                        var items        = scannedItems.FindAll(item => item.ProductId == pId);
                        var discountType = Products.Find(p => p.ProductId == pId).DiscountType;

                        calculator = PriceCalculatorFactory.GetPriceCalculator(discountType);
                        if (calculator != null)
                        {
                            var discount = Discounts.Find(dis => dis.ProductId == pId);
                            //Call the Calculator
                            calculator.CalculatePrice(items, discount);
                        }
                    }
                });
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Exception during Checkout process", ex);
            }

            PrintReceipt();
        }
Exemplo n.º 11
0
 public double CalculatePrice()
 {
     return(Math.Round(_priceCalculator.CalculatePrice(ShoppingList) + _priceCalculator.CalculateTax(ShoppingList), 2));
 }
Exemplo n.º 12
0
 public decimal CalculatePrice(int itemsCount)
 {
     return((itemsCount / volumeSize) * volumePrice + singleUnitPriceCalculator.CalculatePrice(itemsCount % volumeSize));
 }
Exemplo n.º 13
0
 public decimal GetTotalPrice(decimal discountRate)
 {
     return(_priceCalculator.CalculatePrice(_productsCount, discountRate));
 }
Exemplo n.º 14
0
        public void Confirm5()
        {
            var result = priceCalculator.CalculatePrice();

            this.paymentGateway.CapturePayment(result.Amount, result.VatAmount);
        }
Exemplo n.º 15
0
 public decimal GetTotalCost()
 {
     return(_orderItems.Sum(orderItem => _priceCalculator.CalculatePrice(CurrentCustomer, orderItem)));
 }
 public decimal GetTotalPrice(decimal discountRate)
 {
     return(priceCalculator.CalculatePrice(itemsCount, discountRate));
 }
 public decimal CalculateTotal()
 {
     return(_priceCalculator.CalculatePrice(_orderList));
 }
Exemplo n.º 18
0
 /// <summary>
 /// Use the price calculator specified to get the total price.
 /// </summary>
 /// <returns></returns>
 public decimal GetTotalPrice()
 {
     return(priceCalculator.CalculatePrice(itemsCount));
 }
Exemplo n.º 19
0
 public void CalculatePrice()
 {
     PriceCalculator = PriceCalculator.CalculatePrice(CartProducts);
     CartProducts    = PriceCalculator.UpdatedCartProducts;
     CartTotalValue  = PriceCalculator.TotalOrderValue;
 }