Beispiel #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;
            }
        }
Beispiel #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);
        }
Beispiel #3
0
        public async Task <IActionResult> PointExch(MemberPointInfoViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (model.ExchAmount < 0)
                {
                    return(ErrorMessage.BadRequestJsonResult("ExchAmount must be greater than 0."));
                }

                MemberPointInfoViewModel pointInfo = await GetMemberPointInfo(model.MemberID);

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

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

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


                MemberPointInfoViewModel newPointInfo = await GetMemberPointInfo(model.MemberID);

                newPointInfo.IDCard     = model.IDCard;
                newPointInfo.MemberName = model.MemberName;
                return(Json(newPointInfo));
            }
            return(ErrorMessage.BadRequestJsonResult(ModelState.Values.SelectMany(x => x.Errors)));
        }
Beispiel #4
0
        private async Task <SellMemberPointViewModel> AddMemberPoint(SaleToCustomerDetail saleToCustomerDetail)
        {
            MemberPointRule pointRule = await this.GetPointRule();

            // Left JOIN

            /*
             * var customers = await (from m1 in _applicationDbContext.Members
             *                     join m2 in _applicationDbContext.Members
             *                         on m1.ReferenceMemberID equals m2.MemberID
             *                      select new {
             *                          MemberID = m1.MemberID,
             *                          MemberName = m1.Name,
             *                          MemberLevel = m1.Level,
             *
             *                          Up1ID = m2.MemberID,
             *                          Up1Name = m2.Name,
             *                          Up1Level = m2.Level,
             *                          Up1ReferenceMemberID = m2.ReferenceMemberID
             *                      } into M12
             *                     join m3 in _applicationDbContext.Members
             *                         on M12.Up1ReferenceMemberID equals m3.MemberID into M23
             *                     from m5 in M23.DefaultIfEmpty()
             *                     where M12.MemberID.Equals(saleToCustomerDetail.Sale.Customer.MemberID,
             *                         StringComparison.InvariantCultureIgnoreCase)
             *                     select new SellMemberPointViewModel
             *                     {
             *                         MemberID = M12.MemberID,
             *                         MemberName = M12.MemberName,
             *                         MemberLevel = M12.MemberLevel,
             *
             *                         Up1ID = M12.Up1ID,
             *                         Up1Name = M12.Up1Name,
             *                         Up1Level = M12.Up1Level,
             *
             *                         Up2ID = m5.MemberID,
             *                         Up2Name = m5.Name,
             *                         Up2Level = m5.Level,
             *                     }).FirstOrDefaultAsync();
             *
             */
            var customers = GetCustomersFromSqlCommand(_applicationDbContext.Database.AsRelational(),
                                                       saleToCustomerDetail.Sale.Customer.MemberID);


            if (customers == null)
            {
                return(new SellMemberPointViewModel
                {
                    MemberID = "",
                    MemberName = "",
                    MemberLevel = "",

                    Up1ID = "",
                    Up1Name = "",
                    Up1Level = "",

                    Up2ID = "",
                    Up2Name = "",
                    Up2Level = ""
                });
            }

            if (string.IsNullOrWhiteSpace(customers.MemberID) == false)
            {
                MemberPoint menberPoint = new MemberPoint(saleToCustomerDetail);
                menberPoint.Owner = new Member {
                    MemberID = customers.MemberID
                };
                menberPoint.UseableDate = pointRule.CalcAvailableDate(menberPoint.DealDate);
                menberPoint.Quantity    = pointRule.Calc(customers.MemberLevel, LevelRelation.Self, saleToCustomerDetail.Price);
                menberPoint.ID          = IDGenerator.GetMemberPointIDGenerator(this._applicationDbContext).GetNext();

                var pointInfo = await GetMemberPointInfo(menberPoint.Owner.MemberID);

                if (pointInfo != null)
                {
                    menberPoint.CurrentTotalQuantity = pointInfo.PointTotal;
                }


                this._applicationDbContext.MemberPoint.Add(menberPoint);

                customers.PointCount = menberPoint.Quantity;
            }

            if (string.IsNullOrWhiteSpace(customers.Up1ID) == false)
            {
                MemberPoint menberPoint = new MemberPoint(saleToCustomerDetail);
                menberPoint.Owner = new Member {
                    MemberID = customers.Up1ID
                };
                menberPoint.UseableDate = pointRule.CalcAvailableDate(menberPoint.DealDate);
                menberPoint.Quantity    = pointRule.Calc(customers.Up1Level,
                                                         LevelRelation.Son, saleToCustomerDetail.Price);
                menberPoint.ID = IDGenerator.GetMemberPointIDGenerator(this._applicationDbContext).GetNext();

                var pointInfo = await GetMemberPointInfo(menberPoint.Owner.MemberID);

                if (pointInfo != null)
                {
                    menberPoint.CurrentTotalQuantity = pointInfo.PointTotal;
                }

                this._applicationDbContext.MemberPoint.Add(menberPoint);
                customers.Up1PointCount = menberPoint.Quantity;
            }

            if (string.IsNullOrWhiteSpace(customers.Up2ID) == false)
            {
                MemberPoint menberPoint = new MemberPoint(saleToCustomerDetail);
                menberPoint.Owner = new Member {
                    MemberID = customers.Up2ID
                };
                menberPoint.UseableDate = pointRule.CalcAvailableDate(menberPoint.DealDate);
                menberPoint.Quantity    = pointRule.Calc(customers.Up2Level,
                                                         LevelRelation.Grandson, saleToCustomerDetail.Price);
                menberPoint.ID = IDGenerator.GetMemberPointIDGenerator(this._applicationDbContext).GetNext();

                var pointInfo = await GetMemberPointInfo(menberPoint.Owner.MemberID);

                if (pointInfo != null)
                {
                    menberPoint.CurrentTotalQuantity = pointInfo.PointTotal;
                }

                this._applicationDbContext.MemberPoint.Add(menberPoint);

                customers.Up2PointCount = menberPoint.Quantity;
            }

            return(customers);
        }