public void CreateOrder_Should_Not_Validated_When_ProductCode_Is_NullOrEmpty(string productCode)
        {
            var createOrderCommand = new CreateOrderCommand
            {
                ProductCode = productCode,
                Quantity    = FakeObjects.Instance.Random.Int(1, 10)
            };
            var validationResult = _validator.Validate(createOrderCommand);

            validationResult.Errors.Any(x => x.PropertyName == nameof(createOrderCommand.ProductCode)).Should().Be(true);
        }
Esempio n. 2
0
        public CreateOrderModel CreateOrder(CreateOrderModel model)
        {
            var validator      = new CreateOrderValidator();
            var validateResult = validator.Validate(model);

            if (validateResult.IsValid)
            {
                return(model);
            }

            return(null);
        }
Esempio n. 3
0
        public ActionResult PreviewAndPay(PreviewViewModel model)
        {
            var cart = shoppingService.GetCurrentShoppingCart();

            if (cart.IsEmpty)
            {
                ModelState.AddModelError("cart.empty", ResHelper.GetString("DancingGoatMvc.Checkout.EmptyCartError"));

                var viewModel = checkoutService.PreparePreviewViewModel(model.PaymentMethod);
                return(View("PreviewAndPay", viewModel));
            }

            if (!checkoutService.IsPaymentMethodValid(model.PaymentMethod.PaymentMethodID))
            {
                ModelState.AddModelError("PaymentMethod.PaymentMethodID", ResHelper.GetString("DancingGoatMvc.Payment.PaymentMethodRequired"));
            }
            else
            {
                shoppingService.SetPaymentOption(model.PaymentMethod.PaymentMethodID);
            }

            var validator = new CreateOrderValidator(cart, skuInfoProvider, countryInfoProvider, stateInfoProvider);

            if (!validator.Validate())
            {
                ProcessCheckResult(validator.Errors);
            }

            if (!ModelState.IsValid)
            {
                var viewModel = checkoutService.PreparePreviewViewModel(model.PaymentMethod);
                return(View("PreviewAndPay", viewModel));
            }

            try
            {
                shoppingService.CreateOrder();
            }
            catch (InvalidOperationException ex)
            {
                ModelState.AddModelError("cart.createordererror", ex.Message);
                var viewModel = checkoutService.PreparePreviewViewModel(model.PaymentMethod);
                return(View("PreviewAndPay", viewModel));
            }

            return(RedirectToAction("ThankYou"));
        }
Esempio n. 4
0
        public ActionResult PreviewAndPay(PreviewViewModel model, [FromServices] IStringLocalizer <SharedResources> localizer)
        {
            var cart = shoppingService.GetCurrentShoppingCart();

            if (cart.IsEmpty)
            {
                ModelState.AddModelError("cart.empty", localizer["Please add some item to your shopping cart."]);

                var viewModel = checkoutService.PreparePreviewViewModel(model.PaymentMethod);
                return(View("PreviewAndPay", viewModel));
            }

            if (!checkoutService.IsPaymentMethodValid(model.PaymentMethod.PaymentMethodID))
            {
                ModelState.AddModelError("PaymentMethod.PaymentMethodID", localizer["Select payment method"]);
            }
            else
            {
                shoppingService.SetPaymentOption(model.PaymentMethod.PaymentMethodID);
            }

            var validator = new CreateOrderValidator(cart, skuInfoProvider, countryInfoProvider, stateInfoProvider);

            if (!validator.Validate())
            {
                ProcessCheckResult(validator.Errors);
            }

            if (!ModelState.IsValid)
            {
                var viewModel = checkoutService.PreparePreviewViewModel(model.PaymentMethod);
                return(View("PreviewAndPay", viewModel));
            }

            try
            {
                shoppingService.CreateOrder();
            }
            catch (InvalidOperationException ex)
            {
                ModelState.AddModelError("cart.createordererror", ex.Message);
                var viewModel = checkoutService.PreparePreviewViewModel(model.PaymentMethod);
                return(View("PreviewAndPay", viewModel));
            }

            return(RedirectToAction("ThankYou"));
        }
Esempio n. 5
0
        public ActionResult PreviewAndPay(PreviewViewModel model)
        {
            var cart = mShoppingService.GetCurrentShoppingCart();

            if (cart.IsEmpty)
            {
                ModelState.AddModelError("cart.empty", ResHelper.GetString("DancingGoatMvc.Checkout.EmptyCartError"));

                var viewModel = mCheckoutService.PreparePreviewViewModel(model.PaymentMethod);
                return(View("PreviewAndPay", viewModel));
            }

            if (!mCheckoutService.IsPaymentMethodValid(model.PaymentMethod.PaymentMethodID))
            {
                ModelState.AddModelError("PaymentMethod.PaymentMethodID", ResHelper.GetString("DancingGoatMvc.Payment.PaymentMethodRequired"));
            }
            else
            {
                mShoppingService.SetPaymentOption(model.PaymentMethod.PaymentMethodID);
            }

            var validator = new CreateOrderValidator(cart);

            if (!validator.Validate())
            {
                ProcessCheckResult(validator.Errors);
            }

            if (!ModelState.IsValid)
            {
                var viewModel = mCheckoutService.PreparePreviewViewModel(model.PaymentMethod);
                return(View("PreviewAndPay", viewModel));
            }

            mShoppingService.CreateOrder();

            return(RedirectToAction("ThankYou"));
        }