Ejemplo n.º 1
0
        public void AddDataToJson(SkuIdPrice skuIdPrice, string filePath)
        {
            string jsonactive = JsonConvert.SerializeObject(skuIdPrice);
            bool   blnpath    = false;

            if (!File.Exists(filePath))
            {
                blnpath = true;
            }
            else
            {
                string text = File.ReadAllText(filePath);
                text = text.Replace("]", ",");
                File.WriteAllText(filePath, text);
            }

            using (var tw = new StreamWriter(filePath, true))
            {
                if (blnpath)
                {
                    jsonactive = "[" + jsonactive + "]";
                }
                else
                {
                    jsonactive = jsonactive + "]";
                }
                tw.WriteLine(jsonactive.ToString());
                tw.Close();
            }
        }
Ejemplo n.º 2
0
        public SkuIdPrice GetSkuIdPrice(int skuId)
        {
            SkuIdPrice skuidPrice =
                (from l in Global.skuIdPrice
                 where l.skuid == skuId
                 select new SkuIdPrice
            {
                unitprice = l.unitprice,
            }).FirstOrDefault();

            return(skuidPrice);
        }
Ejemplo n.º 3
0
        public void ScenarioCCTest()
        {
            if (File.Exists(SkuIddatapath))
            {
                File.Delete(SkuIddatapath);
            }
            JsonParser.JsonParserToList(path, promotionData);
            SkuIdPrice   skuidPrice = new SkuIdPrice();
            blSkuIdPrice skuIdPrice = new blSkuIdPrice();

            skuidPrice = skuIdPrice.GetSkuIdPrice(3);
            calculateResult.AddDataToJson(skuidPrice, SkuIddatapath);


            Global.resultSkuIdPrice = JsonParser.JsonParserToActivePromotion(SkuIddatapath);

            Assert.Equal(30, calculateResult.CalculateFinalResult(4, 4, 1, SkuIddatapath));
        }
Ejemplo n.º 4
0
        public int CalculateFinalResult(int skuId, int promptioid, int orderUnit, string filePath)
        {
            int calculateValue = 0;

            try
            {
                ActivePromotion activePromotion = blActivePromotion.GetActivePromotion(promptioid);

                blSkuIdPrice blSkuIdPrice   = new blSkuIdPrice();
                SkuIdPrice   skuidPrice     = blSkuIdPrice.GetSkuIdPrice(skuId);
                int          finalUnitPrice = 0;
                if (activePromotion.SubPromotionId != 0)
                {
                    if (Global.resultSkuIdPrice != null)
                    {
                        if (Global.resultSkuIdPrice.Exists(x => x.skuid == activePromotion.SubPromotionId))
                        {
                            finalUnitPrice       = activePromotion.Promotions;
                            skuidPrice.unitprice = finalUnitPrice;
                            UpdateJson(activePromotion.SubPromotionId, 0, filePath);
                            AddDataToJson(skuidPrice, filePath);
                            return(finalUnitPrice);
                        }
                    }
                    finalUnitPrice = skuidPrice.unitprice;
                }
                else
                {
                    finalUnitPrice = activePromotion.unit;
                }

                int remainingUnit = orderUnit % finalUnitPrice * skuidPrice.unitprice;
                int groupedUnit   = orderUnit / finalUnitPrice * activePromotion.Promotions;
                calculateValue       = remainingUnit + groupedUnit;
                skuidPrice.unitprice = calculateValue;
                AddDataToJson(skuidPrice, filePath);
            }
            catch (System.Exception)
            {
                throw;
            }

            return(calculateValue);
        }
Ejemplo n.º 5
0
        public int CalculateFinalResult(int skuId, int promptioid, int orderUnit)
        {
            int calculateValue = 0;

            try
            {
                blActivePromotion blActivePromotion = new blActivePromotion();
                ActivePromotion   activePromotion   = blActivePromotion.GetActivePromotion(promptioid);

                blSkuIdPrice blSkuIdPrice = new blSkuIdPrice();
                SkuIdPrice   skuidPrice   = blSkuIdPrice.GetSkuIdPrice(skuId);
                //int orderUnit = Convert.ToInt32(txtUnit.Text);
                int remainingUnit = orderUnit % activePromotion.unit * skuidPrice.unitprice;
                int groupedUnit   = orderUnit / activePromotion.unit * activePromotion.Promotions;

                calculateValue = remainingUnit + groupedUnit;
            }
            catch (System.Exception)
            {
                throw;
            }
            return(calculateValue);
        }