Exemplo n.º 1
0
 public MemberPoint(SaleToCustomerDetail saleDetail)
     : this()
 {
     Product = saleDetail.Prodect;
     ProductBuyer = saleDetail.Sale.Customer;
     DealDate = saleDetail.Sale.DealDate;
     OperationBy = saleDetail.Sale.SellingAgents;
     Type = "FromSale";
 }
Exemplo n.º 2
0
        private async Task<SellMemberPointViewModel> AddMemberPoint(SaleToCustomerDetail saleToCustomerDetail)
        {
            MemberPointRule pointRule = await this.GetPointRule();

            // Left JOIN
            var customers = await (from m1 in this.AppDbContext.Members
                                   join m2 in this.AppDbContext.Members
                                       on m1.ReferenceMemberID equals m2.MemberID
                                   where m1.MemberID.Equals(saleToCustomerDetail.Sale.Customer.MemberID, StringComparison.InvariantCultureIgnoreCase)
                                   select m2 into M01
                                   join m3 in this.AppDbContext.Members
                                       on M01.ReferenceMemberID equals m3.MemberID into M02
                                   from m4 in M02.DefaultIfEmpty()
                                   select new
                                   {
                                       MemberID = M01.MemberID,
                                       MemberName = M01.Name,
                                       MemberLevel = M01.Level,

                                       Up1ID = m4.MemberID,
                                       Up1Name = m4.Name,
                                       Up1Level = m4.Level,
                                       Up1ReferenceMemberID = m4.ReferenceMemberID
                                   } into M03
                                   join m5 in this.AppDbContext.Members
                                       on M03.Up1ReferenceMemberID equals m5.MemberID into M04
                                   from m6 in M04.DefaultIfEmpty()
                                   select new SellMemberPointViewModel
                                   {
                                       MemberID = M03.MemberID,
                                       MemberName = M03.MemberName,
                                       MemberLevel = M03.MemberLevel,

                                       Up1ID = M03.Up1ID,
                                       Up1Name = M03.Up1Name,
                                       Up1Level = M03.Up1Level,

                                       Up2ID = m6.MemberID,
                                       Up2Name = m6.Name,
                                       Up2Level = m6.Level,
                                   }).FirstOrDefaultAsync();


            //var customers = GetCustomersFromSqlCommand(AppDbContext.Database.Connection, 
            //      saleToCustomerDetail.Sale.Customer.MemberID);


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

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

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

            customers.PointCount = await AddOneMemberPoint(saleToCustomerDetail, pointRule,
                customers.MemberID, customers.MemberLevel, LevelRelation.Self);

            customers.Up1PointCount = await AddOneMemberPoint(saleToCustomerDetail, pointRule,
                customers.Up1ID, customers.Up1Level, LevelRelation.Son);

            customers.Up2PointCount = await AddOneMemberPoint(saleToCustomerDetail, pointRule, 
                customers.Up2ID, customers.Up2Level, LevelRelation.Grandson);

            return customers;
        }
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;
        }
Exemplo n.º 4
0
        private async Task<ActionResult> DoSell(SellToCustomerViewModel model)
        {
            var loginUser = await GetCurrentUserAsync();

            ProductDesc productDesc = await AppDbContext.ProductDesc
                                        .Where(m => m.ID.Equals(model.MattressTypeID,
                                                StringComparison.InvariantCultureIgnoreCase))
                                        .FirstOrDefaultAsync();
            Mattress mattress = new Mattress
            {
                ID = model.MattressID,
                TypeDesc = productDesc,
                RegisterDate = model.SaleDate,
                SaleDate = model.SaleDate,
            };

            SaleToCustomerDetail saleToCustomerDetail = new SaleToCustomerDetail
            {
                Gifts = model.Gifts,
                DeliveryAddress = model.DeliveryAddress,
                Prodect = mattress,
                Price = productDesc.Price,
                CashCoupon = model.IsUseCashCoupon ? 1000 : 0

            };
            SaleToCustomer saleToCustomer = new SaleToCustomer
            {
                ID = IDGenerator.GetSaleToCustomerIDGenerator(AppDbContext).GetNext(),
                Customer = this.AppDbContext.FindOrAttachToLocal(model.CustomerID ),
                SellingAgents = this.AppDbContext.FindOrAttachToLocal(loginUser.UserName),
                DealDate = model.SaleDate,
            };

            saleToCustomerDetail.Sale = saleToCustomer;
            saleToCustomer.DetailItems.Add(saleToCustomerDetail);

           // this.AppDbContext.TryToAttach(saleToCustomer.Customer, (l, r) => r.MemberID.Equals(l.MemberID));
          //  this.AppDbContext.TryToAttach(saleToCustomer.SellingAgents, (l, r) => r.MemberID.Equals(l.MemberID));
            //AppDbContext.Members.Attach(saleToCustomer.Customer);
           // AppDbContext.Members.Attach(saleToCustomer.SellingAgents);

            AppDbContext.Mattress.Add(mattress);
            AppDbContext.SaleToCustomer.Add(saleToCustomer);
            AppDbContext.SaleToCustomeDetails.Add(saleToCustomerDetail);

            var pointItems = await AddMemberPoint(saleToCustomerDetail);

            AppDbContext.SaveChanges();

            return Json(new {
                    saleToCustomerID = saleToCustomer.ID,
                    memberPointItems = pointItems,
                    sellMattressData = new {
                        MattressID= mattress.ID,
                        MattressTypeName= mattress.TypeDesc.DisplayName,
                        DeliveryAddress= saleToCustomerDetail.DeliveryAddress,
                        CustomerID= saleToCustomer.Customer.MemberID,
                        SaleDate= saleToCustomer.DealDate.Date.ToString("yyyy'-'MM'-'dd"),
                        Gifts= saleToCustomerDetail.Gifts,
                        IsUseCashCoupon = model.IsUseCashCoupon
                    },
                JsonRequestBehavior.AllowGet
            });
        }