コード例 #1
0
        public async Task<IActionResult> PointRule(MemberPointRule pointRule)
        {
            if (ModelState.IsValid)
            {
                //MemberPointRule pointRule = null;
               if (pointRule.Level0 == null && Request.Form.Count > 0) {
                    string v = Request.Form["pointRule"];
                    pointRule = MemberPointRule.fromJson(v);
                }

                if (pointRule == null) {
                    return ErrorMessage.BadRequestJsonResult("Cannot parse request context.");
                }

                //MemberPointRule r = JsonConvert.<MemberPointRule>()
                // string bodyStr = GetFromBodyString(Request);
                //MemberPointRule pointRule = MemberPointRule.fromJson(pointRuleValue);
                await AddOrUpdateSetting(SettingName.PointRule.ToString(), "json", pointRule.toJson());
                return Json("OK");
            }
            return ErrorMessage.BadRequestJsonResult(ModelState.Values.SelectMany(x => x.Errors));
        }
コード例 #2
0
        private async Task<decimal> AddOneMemberPoint(SaleToCustomerDetail saleToCustomerDetail,  MemberPointRule pointRule, 
            string customerID, string customerLevel, LevelRelation relation)
        {
            if (string.IsNullOrWhiteSpace(customerID) == false && string.IsNullOrWhiteSpace(customerLevel) == false)
            {
                MemberPoint menberPoint = new MemberPoint(saleToCustomerDetail);
                menberPoint.Owner = this.AppDbContext.FindOrAttachToLocal(customerID);
                menberPoint.UseableDate = pointRule.CalcAvailableDate(menberPoint.DealDate);
                menberPoint.Quantity = pointRule.Calc(customerLevel, relation, saleToCustomerDetail.Price - saleToCustomerDetail.CashCoupon);
                menberPoint.ID = IDGenerator.GetMemberPointIDGenerator(this.AppDbContext).GetNext();

                await CalcCurrentTotal(menberPoint);

                this.AppDbContext.MemberPoint.Add(menberPoint);
                return menberPoint.Quantity;
            }
            return 0;
        }