Esempio n. 1
0
        public async Task <CartTotalViewModel> GetCartTotalParameters(string username)
        {
            var user = this.userRepository
                       .All()
                       .Where(x => x.UserName == username)
                       .FirstOrDefault();

            var subTotal       = this.GetSubtotal(username);
            var clientDiscount = (decimal)this.GetDiscountByCardId(user.ClientCardId);

            if (user == null || subTotal == null)
            {
                return(null);
            }

            var delivery = (decimal)this.GetDeliveryPriceByCardId(user.ClientCardId);

            var subTotalOper = (decimal)subTotal;

            var discount =
                Math.Round(subTotalOper * (decimal)clientDiscount / GlobalConstants.PercentageDivider + user.ClientCard.Voucher, GlobalConstants.FractionalDigits);
            var total =
                Math.Round(subTotalOper - discount + delivery, GlobalConstants.FractionalDigits);

            if (total < 0)
            {
                total = 0;
            }

            var viewModel = new CartTotalViewModel
            {
                Subtotal      = subTotalOper,
                DeliveryPrice = delivery,
                Discount      = discount,
                Total         = total,
            };

            return(viewModel);
        }
        public IViewComponentResult Invoke()
        {
            var model = new CartTotalViewModel
            {
                Subtotal      = 0,
                DeliveryPrice = 0,
                Discount      = 0,
                Total         = 0,
            };

            if (this.User.Identity.Name == null)
            {
                return(this.View(model));
            }

            var viewModel = this.shoppingCartsService.GetCartTotalParameters(this.User.Identity.Name).Result;

            if (viewModel == null)
            {
                return(this.View(model));
            }

            return(this.View(viewModel));
        }