Example #1
0
        private async Task <PromoCode> GetPromocode(string coupon)
        {
            if (!string.IsNullOrEmpty(coupon))
            {
                try
                {
                    var code = await _promoCodeRepository.FindOne(x => x.Coupon.Equals(coupon, StringComparison.InvariantCultureIgnoreCase));

                    if (code != null && code.UsedAmount < code.Amount)
                    {
                        return(code);
                    }
                }
                catch (Exception e)
                {
                    return(null);
                }
            }

            return(null);
        }
Example #2
0
        public async Task <IActionResult> ValidateCoupon(string coupon)
        {
            if (!string.IsNullOrEmpty(coupon))
            {
                try
                {
                    var code = await _promoCodeRepository.FindOne(x => x.Coupon.Equals(coupon, StringComparison.InvariantCultureIgnoreCase));

                    if (code != null && code.UsedAmount < code.Amount)
                    {
                        return(Ok(code));
                    }
                    return(NotFound());
                }
                catch (Exception e)
                {
                    return(View("Error"));
                }
            }

            return(NotFound());
        }