示例#1
0
        public void ReturnTheTotalPrizeMoneyOfACampaing()
        {
            SalesCampaign SalesCampaign = new SalesCampaign(SalesMock.getMockSales());
            int           TMP           = SalesCampaign.GetTotalPrizeMoney();

            Debug.Print(TMP.ToString());
            Assert.AreEqual(19, TMP);
        }
示例#2
0
        public ActionResult Create()
        {
            var model = new SalesCampaign()
            {
                MemberDiscount    = 7.0f,
                NoMmebDiscount    = 7.0f,
                CampaignStartTime = DateTime.Now,
                CampaignEndTime   = DateTime.Now,
            };

            ViewBag.OriginNumberList = model.ProductOriginNumbers.ToList();
            return(PartialView(model));
        }
示例#3
0
        static void Main(string[] args)
        {
            //ReadSalesData();
            var salesLines = ReadSalesData();
            var salesData  = SalesCampaign.PrepareSalesData(salesLines.Select(t => t.ToString()).ToArray());

            var salesCampaing = new SalesCampaign(salesData);

            Console.WriteLine("{0}", salesCampaing.GetTotalPrizeMoney());
            Console.ReadKey();

            //Console.ReadLine();
        }
示例#4
0
        private bool IsValidMarket(SalesCampaign campaign, IMarket market)
        {
            if (market == null)
            {
                return(true);
            }

            if (!market.IsEnabled)
            {
                return(false);
            }

            return(campaign.TargetMarkets?.Contains(market.MarketId.Value, StringComparer.OrdinalIgnoreCase) ?? false);
        }
        private bool IsValidMarket(SalesCampaign campaign, IMarket market)
        {
            if (market == null)
            {
                return(true);
            }

            if (!market.IsEnabled)
            {
                return(false);
            }

            return((campaign.TargetMarkets == null || !campaign.TargetMarkets.Any()) ||
                   campaign.TargetMarkets.Contains(market.MarketId.ToString()));
        }
示例#6
0
        private bool IsValidMarket(SalesCampaign campaign, IMarket market)
        {
            if (market == null)
            {
                return(true);
            }

            if (!market.IsEnabled)
            {
                return(false);
            }

            return((string.IsNullOrEmpty(campaign.TargetMarket) ||
                    campaign.TargetMarket == Constants.AllMarkets) ||
                   market.MarketId.Equals(new MarketId(campaign.TargetMarket)));
        }
示例#7
0
        public JsonResult Create(SalesCampaign saleCap)
        {
            OperationResult resul = new OperationResult(OperationResultType.Error);
            var             prods = Request["saleCap[prod]"];

            if (prods != "all")
            {
                string[] bigProdNumbs = prods.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                //var saleprods = _productContract.Products.Where(c => bigProdNumbs.Contains(c.ProductNumber)).ToList();
                var saleprods = _productOriginNumberContract.OrigNumbs.Where(c => bigProdNumbs.Contains(c.BigProdNum)).ToList();
                saleCap.ProductOriginNumbers = saleprods;
            }


            var storeids = Request["saleCap[StoreIds]"];

            if (!string.IsNullOrEmpty(storeids))
            {
                //判断店铺中是否已存在同名且未过期的活动
                int[]    storeidarr    = storeids.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(c => int.Parse(c)).ToArray();
                var      storeEntities = _storeContract.Stores.Where(s => storeidarr.Contains(s.Id)).ToList();
                DateTime curtime       = DateTime.Now;
                var      camp          = _saleCampaignContract.SalesCampaigns.Where(
                    c =>
                    //storeidarr.Contains((int)c.CampaignStoreId) && c.CampaignName == saleCap.CampaignName && c.CampaignEndTime >= curtime &&
                    c.CampaignName == saleCap.CampaignName && c.CampaignEndTime >= curtime &&
                    !c.IsDeleted).Select(c => c.Id);

                if (camp.Any())
                {
                    resul.Message = "已存在同名且未过期的活动";
                }
                else
                {
                    saleCap.StoresIds  = string.Join(",", storeidarr);
                    saleCap.OperatorId = AuthorityHelper.OperatorId;
                    resul = _saleCampaignContract.Insert(false, saleCap);
                }
            }

            return(Json(resul));
        }
示例#8
0
        private bool IsActive(PromotionData promotion, SalesCampaign campaign)
        {
            var status = _campaignInfoExtractor.GetEffectiveStatus(promotion, campaign);

            return(status == CampaignItemStatus.Active);
        }
示例#9
0
        public JsonResult Update(SalesCampaign saleCap)
        {
            OperationResult resul = new OperationResult(OperationResultType.Error);

            if (saleCap.CampaignNumber == 0)
            {
                return(Json(new OperationResult(OperationResultType.Error, "操作错误-number为0")));
            }
            var saleCampaignEntity = _saleCampaignContract.SalesCampaigns.Where(s => !s.IsDeleted && s.IsEnabled && s.CampaignNumber == saleCap.CampaignNumber)
                                     .Include(s => s.ProductOriginNumbers)
                                     .FirstOrDefault();

            if (saleCampaignEntity == null)
            {
                return(Json(new OperationResult(OperationResultType.Error, "活动不存在")));
            }


            var prods = Request["saleCap[prod]"];

            string[] bigProdNumbs = prods.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var      saleprods    = _productOriginNumberContract.OrigNumbs.Where(c => bigProdNumbs.Contains(c.BigProdNum)).ToList();
            var      beforeNums   = saleCampaignEntity.ProductOriginNumbers.Select(p => p.BigProdNum).ToList();

            var needDel = beforeNums.Except(bigProdNumbs).ToList();
            var needAdd = bigProdNumbs.Except(beforeNums).ToList();

            foreach (var bigProdNum in needDel)
            {
                var entity = saleCampaignEntity.ProductOriginNumbers.First(p => p.BigProdNum == bigProdNum);
                saleCampaignEntity.ProductOriginNumbers.Remove(entity);
            }
            var needAddEntities = _productOriginNumberContract.OrigNumbs.Where(p => !p.IsDeleted && p.IsEnabled && needAdd.Contains(p.BigProdNum)).ToList();

            foreach (var bigProdNumEntity in needAddEntities)
            {
                saleCampaignEntity.ProductOriginNumbers.Add(bigProdNumEntity);
            }


            var storeids = Request["saleCap[StoreIds]"];

            if (string.IsNullOrEmpty(storeids))
            {
                return(Json(new OperationResult(OperationResultType.Error, "活动店铺不可为空")));
            }

            // 参与店铺
            int[] storeidarr    = storeids.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Select(c => int.Parse(c)).ToArray();
            var   storeEntities = _storeContract.Stores.Where(s => storeidarr.Contains(s.Id)).ToList();

            if (storeEntities.Count != storeidarr.Length)
            {
                return(Json(new OperationResult(OperationResultType.Error, "活动店铺id有误")));
            }
            saleCampaignEntity.StoresIds = storeids;

            // 名称
            saleCampaignEntity.CampaignName = saleCap.CampaignName;

            // 日期
            saleCampaignEntity.CampaignStartTime = saleCap.CampaignStartTime;
            saleCampaignEntity.CampaignEndTime   = saleCap.CampaignEndTime;

            // 类型
            saleCampaignEntity.SalesCampaignType = saleCap.SalesCampaignType;

            // 折扣
            saleCampaignEntity.MemberDiscount = saleCap.MemberDiscount;
            saleCampaignEntity.NoMmebDiscount = saleCap.NoMmebDiscount;

            // 描述
            saleCampaignEntity.Descript = saleCap.Descript;

            // 是否可叠加优惠券
            saleCampaignEntity.OtherCashCoupon = saleCap.OtherCashCoupon;

            // 是否可叠加店铺活动
            saleCampaignEntity.OtherCampaign = saleCap.OtherCampaign;

            var res = _saleCampaignContract.Update(saleCampaignEntity);

            return(Json(res));
        }
示例#10
0
        public void ReturnTrueForInvalidCampaignLength()
        {
            int campaignLen = 60000;

            Assert.IsFalse(SalesCampaign.CampaignLengthCheck(campaignLen));
        }
示例#11
0
        public void ReturnTrueForValidCampaignLength()
        {
            int campaignLen = 4000;

            Assert.IsTrue(SalesCampaign.CampaignLengthCheck(campaignLen));
        }
        private bool IsActive(PromotionData promotion, SalesCampaign campaign)
        {
            var status = _campaignInfoExtractor.GetEffectiveStatus(promotion, campaign);

            return status == CampaignItemStatus.Active;
        }
        private bool IsValidMarket(SalesCampaign campaign, IMarket market)
        {
            if (market == null)
            {
                return true;
            }

            if (!market.IsEnabled)
            {
                return false;
            }

            return (string.IsNullOrEmpty(campaign.TargetMarket) ||
                    campaign.TargetMarket == Constants.AllMarkets) ||
                    market.MarketId.Equals(new MarketId(campaign.TargetMarket));
        }