示例#1
0
        public CouponsPage()
        {
            InitializeComponent();

            vm = new CouponsViewModel();
            vm.Initialize(this);
            BindingContext = vm;
        }
示例#2
0
        public virtual CouponsViewModel GetCouponsViewModel(
            Overture.ServiceModel.Orders.Cart cart,
            CultureInfo cultureInfo,
            bool includeMessages)
        {
            if (cart?.Coupons?.FirstOrDefault() == null)
            {
                return(new CouponsViewModel());
            }

            List <Coupon> coupons = cart.Coupons;

            var couponsVm = new CouponsViewModel
            {
                ApplicableCoupons = new List <CouponViewModel>(),
                Messages          = new List <CartMessageViewModel>()
            };

            var allRewards = GetAllRewards(cart.GetActiveShipments().ToList());

            foreach (var coupon in coupons)
            {
                if (IsCouponValid(coupon))
                {
                    var reward   = allRewards.FirstOrDefault(r => r.PromotionId == coupon.PromotionId);
                    var couponVm = MapCoupon(coupon, reward, cultureInfo);
                    couponsVm.ApplicableCoupons.Add(couponVm);
                }
                else if (includeMessages)
                {
                    var message = GetInvalidCouponMessage(coupon, cultureInfo);
                    couponsVm.Messages.Add(message);
                }
            }
            return(couponsVm);
        }