Exemplo n.º 1
0
 private async Task CalcCurrentTotal(MemberPoint menberPoint)
 {
     var pointInfo = await GetMemberPointInfo(menberPoint.Owner.MemberID);
     if (pointInfo != null)
     {
         menberPoint.CurrentTotalQuantity = pointInfo.PointTotal + menberPoint.Quantity;
     }
     else
     {
         menberPoint.CurrentTotalQuantity = menberPoint.Quantity;
     }
 }
Exemplo n.º 2
0
        public async Task<ActionResult> PointExch(MemberPointInfoViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.ExchAmount < 0) {
                    return JsonMessage.BadRequestJsonResult("ExchAmount must be greater than 0.");
                }

                MemberPointInfoViewModel pointInfo = await GetMemberPointInfo(model.MemberID);

                if (pointInfo == null || pointInfo.UsablePoint < model.ExchAmount) {
                    return JsonMessage.BadRequestJsonResult("ExchAmount is greater than UsablePoint.");
                }

                MemberPoint exchPoint = new MemberPoint();
                exchPoint.ID = IDGenerator.GetMemberPointIDGenerator(AppDbContext).GetNext();
                exchPoint.OwnerMemberID = model.MemberID ;
                exchPoint.Type = "PointExch";
                exchPoint.OperationBy = this.AppDbContext.FindOrAttachToLocal((await this.GetCurrentUserAsync()).UserName);
                exchPoint.Quantity = -model.ExchAmount;
                exchPoint.CurrentTotalQuantity = pointInfo.PointTotal;

                this.AppDbContext.MemberPoint.Add(exchPoint);
                this.AppDbContext.SaveChanges();


                MemberPointInfoViewModel newPointInfo = await GetMemberPointInfo(model.MemberID);
                newPointInfo.IDCard = model.IDCard;
                newPointInfo.MemberName = model.MemberName;
                return Json(newPointInfo, JsonRequestBehavior.AllowGet);
            }
            return JsonMessage.BadRequestJsonResult(ModelState.Values.SelectMany(x => x.Errors));
        }
Exemplo n.º 3
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;
        }