Example #1
0
        public IActionResult Post([FromForm] CreateOrderDto dto)
        {
            try
            {
                _createOrder.Execute(dto);
                return(Ok());
            }
            catch (EntityNotFoundException e)
            {
                return(NotFound(e.Message));
            }
            catch (EntityMissmatchException e)
            {
                if (e.Message.Contains("count"))
                {
                    return(BadRequest(e.Message));
                }

                return(UnprocessableEntity(e.Message));
            }
            catch (ProductNotAvailableException e)
            {
                return(BadRequest(e.Message));
            }
            catch (InvalidInputException e)
            {
                return(BadRequest(e.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
Example #2
0
        public IActionResult Insert([FromForm] CreateOrderDto dto)
        {
            try
            {
                _createOrder.Execute(dto);
                return(Redirect("~/Offers/Create"));
            }
            catch (EntityNotFoundException e)
            {
                TempData["message"] = e.Message;
                return(Redirect("~/Offers/Create"));
            }
            catch (EntityMissmatchException e)
            {
                if (e.Message.Contains("count"))
                {
                    TempData["message"] = e.Message;
                    return(Redirect("~/Offers/Create"));
                }

                TempData["message"] = e.Message;
                return(Redirect("~/Offers/Create"));
            }
            catch (ProductNotAvailableException e)
            {
                TempData["message"] = e.Message;
                return(Redirect("~/Offers/Create"));
            }
            catch (InvalidInputException e)
            {
                TempData["message"] = e.Message;
                return(Redirect("~/Offers/Create"));
            }
            catch (Exception e)
            {
                TempData["message"] = e.Message;
                return(Redirect("~/Offers/Create"));
            }
        }
        public IActionResult Checkout(CreateOrderViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var shoppingCartItems = _getShoppingCartItemsListQuery.Execute(_cartIdProvider.CartId);

            if (!shoppingCartItems.Any())
            {
                ModelState.AddModelError("", "You cart is empty.Add some goods first");
            }

            var userId = _getApplicationUserId.Execute(HttpContext.User);

            _saveApplicationUserDetails.Execute(userId, viewModel);

            var orderModel = new CreateOrderModel(userId, _cartIdProvider.CartId);

            _createOrderCommand.Execute(orderModel);

            return(RedirectToAction("CheckoutComplete", new { userId, userEmail = viewModel.Email }));
        }