Esempio n. 1
0
        public void CreateOrderTest()
        {
            var objPromotionEngine = new PromotionEngineCartController();
            SkuItemViewModel      objSkuItemViewModel = new SkuItemViewModel();
            SkuPromotionItemModel objPromotionModel   = new SkuPromotionItemModel {
                UnitA = 4, UnitB = 3, UnitC = 2, UnitD = 5
            };

            objSkuItemViewModel.PromotionItemVM = objPromotionModel;

            var Res = objPromotionEngine.CreateOrder(objSkuItemViewModel);

            Assert.IsNotNull(Res);
        }
Esempio n. 2
0
        public ActionResult CreateOrder(SkuItemViewModel model)
        {
            if (ModelState.IsValid)
            {
                SkuPromotionItemModel skuPromotionModel = model.PromotionItemVM;

                _skuItemList = new List <SkuItemModel>();
                int promotionType, TotalAmountA, TotalAmountB, TotalAmountC, TotalAmountD = 0;
                promotionType = (int)SkuType.activePromotion.A;
                TotalAmountA  = TotalAmount(skuPromotionModel.UnitA, promotionType);
                _skuItemList.Add(new SkuItemModel()
                {
                    Unit = skuPromotionModel.UnitA + "A", Price = TotalAmountA
                });
                promotionType = (int)SkuType.activePromotion.B;
                TotalAmountB  = TotalAmount(skuPromotionModel.UnitB, promotionType);
                _skuItemList.Add(new SkuItemModel()
                {
                    Unit = skuPromotionModel.UnitB + "B", Price = TotalAmountB
                });
                if (skuPromotionModel.UnitC > 0 && skuPromotionModel.UnitD == 0)
                {
                    promotionType = (int)SkuType.activePromotion.C;
                    TotalAmountC  = TotalAmount(skuPromotionModel.UnitC, promotionType);
                    _skuItemList.Add(new SkuItemModel()
                    {
                        Unit = skuPromotionModel.UnitC + "C", Price = TotalAmountC
                    });
                }
                if (skuPromotionModel.UnitC == 0)
                {
                    _skuItemList.Add(new SkuItemModel()
                    {
                        Unit = skuPromotionModel.UnitC + "C", Price = 0
                    });
                }
                if (skuPromotionModel.UnitC == 0 && skuPromotionModel.UnitD > 0)
                {
                    promotionType = (int)SkuType.activePromotion.D;
                    TotalAmountD  = TotalAmount(skuPromotionModel.UnitD, promotionType);
                    _skuItemList.Add(new SkuItemModel()
                    {
                        Unit = skuPromotionModel.UnitD + "D", Price = TotalAmountD
                    });
                }
                if (skuPromotionModel.UnitD == 0)
                {
                    _skuItemList.Add(new SkuItemModel()
                    {
                        Unit = skuPromotionModel.UnitD + "D", Price = 0
                    });
                }
                if (skuPromotionModel.UnitC > 0 && skuPromotionModel.UnitD > 0)
                {
                    promotionType = (int)SkuType.activePromotion.CD;
                    TotalAmountD  = TotalAmount(skuPromotionModel.UnitD, promotionType);
                    _skuItemList.Add(new SkuItemModel()
                    {
                        Unit = skuPromotionModel.UnitC + "C and " + skuPromotionModel.UnitD + "D", Price = TotalAmountD
                    });
                }

                SkuItemResultModel smodel = new SkuItemResultModel();
                model.ResultSetVM            = new SkuItemResultModel();
                model.ResultSetVM.lstSkuItem = _skuItemList;
            }
            return(View(model));
        }