Пример #1
0
        public async Task<bool> ValidateCoupones(string userId, FullOrderModel order)
        {
            CouponesProvider couponesProvider = new CouponesProvider();
            foreach (CouponeModel coupone in order.Coupones)
            {
                if (!await couponesProvider.CouponeExists(coupone.Name, coupone.Value.Value, coupone.ValueType.Value, coupone.FreeShipping.Value))
                {
                    return false;
                }

                if (!await this.CanUseCoupon(coupone, userId, order))
                {

                }
            }

            return true;
        }
        public async Task<IHttpActionResult> GetDefaultCoupons(ClientOrderModel order)
        {
            if (!this.ModelState.IsValid)
            {
                Logger.Current.LogWarning("Orders.GetDefaultCoupons: invalid model state");

                return this.BadRequest(this.ModelState);
            }

            List<CouponeModel> defaultCoupons = new List<CouponeModel>();
            IIdentity currentIdentity = this.User.Identity;
            bool isAuthenticated = currentIdentity.IsAuthenticated;

            bool isLoyalCustomer = false;
            if (isAuthenticated)
            {
                string currentUserId = currentIdentity.GetUserId();
                using (ApplicationUserManager userManager = Startup.UserManagerFactory())
                {
                    isLoyalCustomer = await userManager.IsInRoleAsync(currentUserId, "LoyalCustomer");
                }
            }

            //Volume discounts can be added here
            CouponesProvider couponesProvider = new CouponesProvider();
            IEnumerable<CouponeModel> coupones = await couponesProvider.GetCoupons(isAuthenticated, isLoyalCustomer);

            return this.Ok(coupones);
        }