Пример #1
0
        public void ScenarioCTest()
        {
            var expectedResult  = 280;
            var scenariArequest = new PromotionRequestViewModel();

            scenariArequest.PurchasedPoduct.Add(new RuleEngineAPI.Application.ViewModels.Promotion.Product()
            {
                CodeName = "A", Quantity = 3
            });
            scenariArequest.PurchasedPoduct.Add(new RuleEngineAPI.Application.ViewModels.Promotion.Product()
            {
                CodeName = "B", Quantity = 5
            });
            scenariArequest.PurchasedPoduct.Add(new RuleEngineAPI.Application.ViewModels.Promotion.Product()
            {
                CodeName = "C", Quantity = 1
            });
            scenariArequest.PurchasedPoduct.Add(new RuleEngineAPI.Application.ViewModels.Promotion.Product()
            {
                CodeName = "D", Quantity = 1
            });
            var promCammand  = new PromotionRuleCommand(scenariArequest);
            var promhandler  = new PromotionRuleCommandHandler(_config);
            var actualResult = promhandler.Handle(promCammand, new System.Threading.CancellationToken()).GetAwaiter().GetResult();

            Assert.IsNotNull(actualResult);
            Assert.AreEqual(expectedResult, actualResult.promotionalPrice);
        }
Пример #2
0
 private BaseResponse <PromotionResponseViewModel> UsePartnerVoucher(PromotionRequestViewModel request)
 {
     using (var http = new HttpClient())
     {
         http.BaseAddress = new Uri("http://apiurl");
         var resp = http.PostAsync("api/voucher/use", new JsonContent(request)).Result;
         return(JsonConvert.DeserializeObject <BaseResponse <PromotionResponseViewModel> >(
                    resp.Content.ReadAsStringAsync().Result));
     }
 }
 public async Task <IActionResult> ApplicablePromotion([FromBody] PromotionRequestViewModel request)
 {
     request.RequestId = Guid.NewGuid().ToString();
     return(Ok(await _mediatR.Send(new PromotionRuleCommand(request))));
 }
Пример #4
0
        public BaseResponse <PromotionResponseViewModel> UseVoucher(Voucher voucherEntity, PromotionRequestViewModel request)
        {
            //Logger.Log("|UseVoucherTransaction| begin method");
            var resp = new BaseResponse <PromotionResponseViewModel>()
            {
                Success = true,
                Message = "Sữ dụng voucher thành công",
                Error   = "Không có lỗi nha"
            };

            using (var trans = new TransactionScope(TransactionScopeOption.Required))
            {
                var brandService = this.Service <IBrandService>();
                var pService     = PromotionService;
                var vService     = VoucherService;
                var brandId      = brandService.GetBrandOfStore(request.StoreId).Id;
                // Update số lượng sử dụng promotion
                var promotion = pService.Get <int>(voucherEntity.PromotionID);
                // Giảm số lượng đang hoạt động
                voucherEntity.UsedQuantity    += 1;
                promotion.VoucherUsedQuantity += 1;
                if (voucherEntity.Quantity <= voucherEntity.UsedQuantity)
                {
                    voucherEntity.Active   = false;
                    voucherEntity.isUsed   = true;
                    voucherEntity.IsGetted = true;
                }
                //Logger.Log("|UseVoucherTransaction| update voucher");
                vService.Update(voucherEntity);
                if (promotion.VoucherQuantity <= promotion.VoucherUsedQuantity)
                {
                    promotion.Active = false;
                }
                pService.Update(promotion);
                //Logger.Log("|UseVoucherTransaction| update promotion");

                //check if voucher is in house or of partner
                if (promotion.ApplyToPartner != null)
                {
                    if (promotion.ApplyToPartner == 0) // temp InHouse id
                    {
                        //use voucher in house
                    }
                    else
                    {
                        var result = UsePartnerVoucher(request);
                        if (!result.Success)
                        {
                            return(result);
                        }
                        resp.Message = result.Message;
                        resp.Data    = result.Data;
                    }
                }
                //Logger.Log("|UseVoucherTransaction| partner confirm result: " + resp.Message + "-" + resp.Error);
                trans.Complete();
                resp.ResultCode = (int)Models.ResultEnum.Success;
                return(resp);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="request"></param>
 public PromotionRuleCommand(PromotionRequestViewModel request)
 {
     PurchaseRequest = request ?? throw new ArgumentNullException(nameof(request));
 }