public Discount Apply(string code)
        {
            var discount = _discount.FindByCode(code);

            if (_discount.IsValid(code))
            {
                _cart.AddDiscount(discount);
                return(discount);
            }
            else
            {
                return(null);
            }
        }
        public IActionResult ApplyDiscount(string code)
        {
            var discount = _discountRepository.FindByCode(code ?? string.Empty);
            var error    = "";

            Discount.ApplyDiscount(_calendarRepository.LocalTime(), _cartRepository.GetItemsAndCatalogProductsTotal(null), discount, out error);

            if (!string.IsNullOrEmpty(error))
            {
                return(BadRequest(error));
            }
            else
            {
                _cartRepository.AddDiscount(discount);
                return(Ok());
            }
        }
Exemple #3
0
        public Discount ApplyDiscount(string code)
        {
            var discount = _discountRepository.FindByCode(code ?? string.Empty);
            var error    = "";

            Discount.ApplyDiscount(_calendarRepository.LocalTime(), _cartRepository.GetTotalWithoutDiscount(null), discount, out error);

            if (!string.IsNullOrEmpty(error))
            {
                return(null);
            }
            else
            {
                _cartRepository.AddDiscount(discount);
                return(discount);
            }
        }