Example #1
0
        public ActionResult ApplyPromoter()
        {
            var enabled = _settingService.GetSettingByKey <bool>(PromotersSettings.Enabled);

            if (!enabled)
            {
                return(View("ClosePromoter"));
            }
            var customer = _customerService.GetCustomerId(this.CustomerId);
            var promoter = customer.GetCustomerAttributeValue <bool>(CustomerAttributeNames.IsPromoter);

            if (promoter)
            {
                return(MyQRCode());
            }

            var myOrders = _orderService.GetAllOrders(customerId: this.CustomerId);
            var model    = new ApplyPromoterModel();

            model.CustomerId = this.CustomerId;
            model.CostTotal  = myOrders.Items.Where(i => i.OrderStatusId == (int)OrderStatus.Complete).Sum(i => i.Subtotal);
            model.Mobile     = customer.Mobile;
            model.OrderCount = myOrders.Items.Count(i => i.OrderStatusId == (int)OrderStatus.Complete);
            model.NickName   = customer.NickName;

            var condition = _settingService.GetSettingByKey <int>(PromotersSettings.ApplyCondition);
            var value     = _settingService.GetSettingByKey <int>(PromotersSettings.ApplyValue);

            switch ((PromoterApplyMode)condition)
            {
            case PromoterApplyMode.Unlimited:
                model.MayBe = true;
                break;

            case PromoterApplyMode.OrderTotal:
                model.MayBe = model.CostTotal >= value;
                break;

            case PromoterApplyMode.OrderCount:
                model.MayBe = model.OrderCount >= value;
                break;

            default:
                model.MayBe = false;
                break;
            }
            return(View(model));
        }
Example #2
0
        public ActionResult Edit(ApplyPromoterModel model)
        {
            var promoter = _applyService.GetPromoterById(model.Id);

            promoter = model.MapTo <ApplyPromoterModel, ApplyPromoter>(promoter);
            using (var unitOfWork = _unitOfWorkManager.Begin())
            {
                _applyService.Update(promoter);
                if (promoter.Audit)
                {
                    var customer = _customerService.GetCustomerId(promoter.CustomerId);
                    customer.SaveCustomerAttribute <bool>(CustomerAttributeNames.IsPromoter, true);
                }

                unitOfWork.Complete();
            }
            return(RedirectToAction("List"));
        }
Example #3
0
        public ActionResult ApplyPromoter(ApplyPromoterModel model)
        {
            var customer = _customerService.GetCustomerId(model.CustomerId);
            var promoter = customer.GetCustomerAttributeValue <bool>(CustomerAttributeNames.IsPromoter);

            if (promoter)
            {
                return(MyQRCode());
            }
            _applyService.Insert(new Domain.Customers.ApplyPromoter
            {
                CustomerId   = model.CustomerId,
                Audit        = false,
                AuditReason  = "",
                CreationTime = DateTime.Now,
                Mobile       = model.Mobile,
                NickName     = model.NickName,
            });

            return(View("PromoterList"));
        }