Ejemplo n.º 1
0
        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);
        }