Ejemplo n.º 1
0
        public void Setup()
        {
            var myJsonString = File.ReadAllText("Items.json");

            TestData        = JsonConvert.DeserializeObject <List <Item> >(myJsonString);
            calculateAmount = new CalculatePrice();
        }
Ejemplo n.º 2
0
        public void TestMethod1()
        {
            CalculatePrice calculateTest = new CalculatePrice();

            decimal result = calculateTest.GetTax(50.00m);

            Assert.AreEqual(3.00m, result);
        }
        /// <summary>
        /// Message to recive a Confirmed Order , Calculate the price and let
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public async Task Consume(OrderConfirmed message, MessageContext context)
        {
            using (OrderDataContext dataContext = new OrderDataContext())
            {
                Data.Model.Order order = dataContext.Orders.Include(p => p.Products).SingleOrDefault(p => p.Id == message.Id);
                if (order == null)
                {
                    Exception ex = new Exception("Order not found");
                    ex.Data.Add("OrderId", message.Id);
                    throw ex;
                }

                var calcualtePrice = new CalculatePrice()
                {
                    Products = order.Products.Select(p => new Product()
                    {
                        ProductId = p.Id,
                        Quantity  = p.Quantity
                    }).ToList()
                };

                //Wait for resolve Notified bug in library ticket id #56487 for adding GUID in exchange
                //var calculatedPrice = await Bus.RequestAsync<CalculatePrice, MessageDirectory.Response.CalculatePrice>(calcualtePrice);
                //order.Amount = calculatedPrice.TotalAmount;
                //dataContext.SaveChanges();

                var products = order.Products.Select(o => new Product()
                {
                    ProductId = o.ProductId, Quantity = o.Quantity
                }).ToList();

                var reqProductionInfos = new ProductInfo()
                {
                    Products = products
                };

                //var resultInfo = await Bus.RequestAsync<ProductInfo, MessageDirectory.Response.ProductInfo>(reqProductionInfos);
                OrderReadyToDeliver orderReady = new OrderReadyToDeliver()
                {
                    Address      = order.Address,
                    Amount       = order.Amount,
                    City         = order.City,
                    CreateDate   = order.CreateDate,
                    DeliveryType = (DeliveryType)order.DeliveryType,
                    Email        = order.Email,
                    PayedAmount  = order.Amount,
                    PhoneNumber  = order.PhoneNumber,
                    //ProductsToPrepare = resultInfo.Products.Select(p => new ProductToPrepare()
                    //{
                    //    ProductName = p.ProductName,
                    //    Quantity = p.Quantity
                    //}).ToList()
                };

                await Bus.PublishAsync(orderReady);
            }
        }
Ejemplo n.º 4
0
        public void AddOrder([FromBody] Cart cart)
        {
            var cal = new CalculatePrice();

            cart.TotalPrice = cal.CalculateEachProduct(cart.Product.Price, cart.Amount);
            //cart.SumPrice = cal.CalculatePriceTotal(carts);
            cart.TotalDiscount = cal.CalculateDiscount(cart);
            //cart.TotalPriceFinal = cal.CalculateFinalPrice(carts);

            carts.Add(cart);
        }
Ejemplo n.º 5
0
        public void TestMethod3()
        {
            List <Product> _products = new List <Product>()
            {
                new Product("A"), new Product("A"), new Product("D"), new Product("B"), new Product("B")
            };
            CalculatePrice             _cp      = new CalculatePrice(_products);
            Dictionary <string, float> _allDisc = _cp.GetDiscount();

            float _result = _allDisc.Values.Max();

            Assert.AreEqual(15, _result);
        }
Ejemplo n.º 6
0
        public void TestMethod1()
        {
            List <Product> _products = new List <Product>()
            {
                new Product("A"), new Product("A"), new Product("B"), new Product("B"), new Product("C"), new Product("D")
            };
            CalculatePrice             _cp      = new CalculatePrice(_products);
            Dictionary <string, float> _allDisc = _cp.GetDiscount();
            float _totalCost = _products.Sum(item => item._price);

            float _result = _totalCost - _allDisc.Values.Max();

            Assert.AreEqual(180, _result);
        }
        private void CalculateAndSendNewPrice()
        {
            IReadOnlyCollection <RepricingInformation> repricingInformations = RepricingInformationCache.Instance.RepricingInformations;

            List <RepricingInformation> inStockRepricingInformations = repricingInformations
                                                                       .Where(x => InventorySupplyCache.Instance.InStockSupplyQuantity(x.SKU) > 0)
                                                                       .ToList();

            List <RepricingInformation> inStockRepricingInformationsWithoutListingOffers = inStockRepricingInformations
                                                                                           .Where(x => !ListingOffersCache.Instance.HasListingOffersForAsin(x.ASIN))
                                                                                           .ToList();

            Dictionary <string, decimal> myPricesForInStockItemsWithoutListingOffers = GetMyPrices(inStockRepricingInformationsWithoutListingOffers.Select(x => x.SKU));

            List <UpdatedItemPrice> newPrices = new List <UpdatedItemPrice>();

            foreach (RepricingInformation repricingInfo in inStockRepricingInformations)
            {
                string asin = repricingInfo.ASIN;
                string sku  = repricingInfo.SKU;

                ListingOffers listingOffers = ListingOffersCache.Instance.GetListingOffers(asin);

                decimal?myPrice = null;

                if (myPricesForInStockItemsWithoutListingOffers.ContainsKey(sku))
                {
                    myPrice = myPricesForInStockItemsWithoutListingOffers[sku];
                }

                UpdatedItemPrice updatedItemPrice = CalculatePrice.CalculateNewPrice(sku, asin, repricingInfo, listingOffers, myPrice);
                if (updatedItemPrice != null)                 // If we can't set a price, this object will be null.
                {
                    decimal newPrice  = updatedItemPrice.UpdatedPrice;
                    decimal?lastPrice = PriceHistoryCache.Instance.GetLastPrice(asin);

                    if ((newPrice > repricingInfo.MinimumPrice) && (newPrice > 4.00m) &&              //// This new price has to be greater than our minimum price and greater than $4.00
                        (!lastPrice.HasValue || lastPrice.Value != newPrice))                         //// This new price has to be not equal to our last updated price.
                    {
                        newPrices.Add(updatedItemPrice);
                    }
                }
            }

            UploadNewPrices(newPrices);
        }
Ejemplo n.º 8
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            var combo = (sender as ComboBox);

            //MessageBox.Show(combo.SelectedItem.ToString());
            //Debug.Assert(combo != null, "combo != null");
            comboBox3.SelectedItem = combo != null && Convert.ToDouble(combo.SelectedItem.ToString()) < 100 ? comboBox3.Items[0] : comboBox3.Items[1];

            //calculate price
            if (combo != null)
            {
                var chargeCalculator = new CalculatePrice(Convert.ToDouble(combo.SelectedItem));
                labelPriceNaira.Location =
                    _currencyLengthLocationDictionary[chargeCalculator.GetPrice().ToString().Length];

                labelPriceNaira.Text = chargeCalculator.ToString();
            }
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Country : iPods Required");
            string userInput = Console.ReadLine();

            string[] countryiPodsRequiredArray = userInput.Split(':');
            var      calculateLogistics        = new CalculateLogistis();
            var      iPodLogisticsDistribution = calculateLogistics.CalculateIPodsLogistics(countryiPodsRequiredArray[0].Trim(), Convert.ToInt32(countryiPodsRequiredArray[1].Trim()));

            if (iPodLogisticsDistribution == null)
            {
                ErrorHandler.DiplayError(Convert.ToInt32(countryiPodsRequiredArray[1].Trim()));
            }
            var priceCalculator = new CalculatePrice();
            var bestPrice       = priceCalculator.CalculateBestPrice(iPodLogisticsDistribution);

            Console.WriteLine("Vest Price = " + bestPrice);
        }
Ejemplo n.º 10
0
 private void HandlePrice(CalculatePrice command)
 {
     Console.WriteLine("Total price: {0}", OrderDetails.Sum(x => x.Price));
 }
Ejemplo n.º 11
0
 static void Main(string[] args)
 {
     CalculatePrice calculate = new CalculatePrice();
 }
        static async Task Main(string[] args)
        {
            Console.WriteLine("Product Reader Console");

            QueueClient queueClient = new QueueClient(AccountDetails.ConnectionString, AccountDetails.QueueName);


            // Create a sample order
            SkuTag[] ordercart = new SkuTag[]
            {
                new SkuTag()
                {
                    Product = "A", Price = (int)Price.A
                },
                new SkuTag()
                {
                    Product = "A", Price = (int)Price.A
                },
                new SkuTag()
                {
                    Product = "A", Price = (int)Price.A
                },
                new SkuTag()
                {
                    Product = "A", Price = (int)Price.A
                },
                new SkuTag()
                {
                    Product = "A", Price = (int)Price.A
                },
                new SkuTag()
                {
                    Product = "B", Price = (int)Price.B
                },
                new SkuTag()
                {
                    Product = "B", Price = (int)Price.B
                },
                new SkuTag()
                {
                    Product = "B", Price = (int)Price.B
                },
                new SkuTag()
                {
                    Product = "B", Price = (int)Price.B
                },
                new SkuTag()
                {
                    Product = "C", Price = (int)Price.C
                },
                new SkuTag()
                {
                    Product = "D", Price = (int)Price.D
                },
                new SkuTag()
                {
                    Product = "C", Price = (int)Price.C
                },
                new SkuTag()
                {
                    Product = "C", Price = (int)Price.C
                },
                new SkuTag()
                {
                    Product = "D", Price = (int)Price.D
                },
                new SkuTag()
                {
                    Product = "D", Price = (int)Price.D
                },
                new SkuTag()
                {
                    Product = "D", Price = (int)Price.D
                }
            };

            // Display the order data.
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Order contains {0} items.", ordercart.Length);
            Console.ForegroundColor = ConsoleColor.Yellow;

            var calculateTotalPrice = CalculatePrice.calculateTotalPriceCart(ordercart, PromotionType.Onproduct);

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Order value = ${0}.", calculateTotalPrice);
            Console.WriteLine();
            Console.ResetColor();



            Console.WriteLine("Press enter to Send to Checkout...");
            Console.ReadLine();

            Console.WriteLine("Reading Products...");
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Cyan;

            var sessionId = Guid.NewGuid().ToString();

            Console.WriteLine($"SessionId: { sessionId }");

            int position = 0;

            while (position < ordercart.Length)
            {
                SkuTag skuidTag = ordercart[position];
                skuidTag.TotalPrice = calculateTotalPrice;
                // Create a new  message from the order item RFID tag.
                var orderJson      = JsonConvert.SerializeObject(skuidTag);
                var skuReadMessage = new Message(Encoding.UTF8.GetBytes(orderJson));

                // Comment in to set message id.
                skuReadMessage.MessageId = skuidTag.SkuId;

                // Comment in to set session id.
                skuReadMessage.SessionId = sessionId;

                // Send the message
                await queueClient.SendAsync(skuReadMessage);

                //Console.WriteLine($"Sent: { orderItems[position].Product }");
                Console.WriteLine($"Sent: { ordercart[position].Product } - MessageId: { skuReadMessage.MessageId }");
                position++;
                if (position == ordercart.Length)
                {
                    var totalJson    = JsonConvert.SerializeObject(calculateTotalPrice);
                    var totalMessage = new Message(Encoding.UTF8.GetBytes(totalJson));
                    totalMessage.MessageId = skuidTag.SkuId;
                    totalMessage.SessionId = sessionId;
                    await queueClient.SendAsync(totalMessage);

                    Console.WriteLine($"Sent: { totalJson } - MessageId: { skuReadMessage.MessageId }");
                }
                Thread.Sleep(100);
            }
        }
Ejemplo n.º 13
0
        public IHttpActionResult Create(string cartNo)
        {
            var cartData = db.Order.Where(x => x.CartNo == cartNo);
            var cartDate = cartData.Where(x => x.CartNo == cartNo).Select(x => x.DateCreated)
                           .FirstOrDefault();
            var customer = db.Customer.FirstOrDefault(x => x.Id == cartData.Select(y => y.Customer.Id).FirstOrDefault());
            List <InvoiceItems> invoice = new List <InvoiceItems>();

            foreach (var item in cartData)
            {
                var itemName = db.Inventory.Where(x => x.Id == item.ItemId).Select(x => x.Name)
                               .FirstOrDefault();
                var itemType = db.Inventory.Where(x => x.Id == item.ItemId).Select(x => x.EquipmentType)
                               .FirstOrDefault();
                int          duration = item.Duration;
                InvoiceItems items    = new InvoiceItems();
                {
                    items.ItemName     = itemName;
                    items.RentDuration = duration;
                    items.RentPrice    = CalculatePrice.Price(itemType, duration);
                    items.BonusPoints  = CalculatePoints.Calculate(itemType);
                }

                invoice.Add(items);
            }
            using (var stream = new MemoryStream())
            {
                StreamWriter writer = new StreamWriter(stream);
                writer.WriteLine("Invoice no: " + cartDate.Ticks);
                writer.WriteLine("-------------------");
                writer.WriteLine("Customer name: " + customer?.CustomerName + ", you have " + customer?.BonusPoints + " points");
                writer.WriteLine("Equipment:");
                writer.WriteLine("-------------------");
                int priceSum  = 0;
                int pointsSum = 0;
                foreach (var item in invoice)
                {
                    writer.WriteLine(item.ItemName + "; " + item.RentDuration + " days; " + item.RentPrice + " €");
                    priceSum  += item.RentPrice;
                    pointsSum += item.BonusPoints;
                }
                writer.WriteLine("-------------------");
                writer.WriteLine("Total: " + priceSum + " €");
                writer.WriteLine("Points earned: " + pointsSum);
                writer.Flush();
                writer.Close();

                var result = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ByteArrayContent(stream.ToArray())
                };
                result.Content.Headers.ContentDisposition =
                    new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
                {
                    FileName = "Invoice.txt"
                };
                result.Content.Headers.ContentType =
                    new MediaTypeHeaderValue("application/octet-stream");

                var response = ResponseMessage(result);

                return(response);
            }
        }
Ejemplo n.º 14
0
        public double CalculateFinalPrice()
        {
            var cal = new CalculatePrice();

            return(cal.CalculateFinalPrice(carts));
        }
Ejemplo n.º 15
0
        public double CalculatePriceTotal()
        {
            var cal = new CalculatePrice();

            return(cal.CalculatePriceTotal(carts));
        }