public ActionResult <Order> AddProductToOrder([FromBody] AddProductToOrder request)
        {
            var response = _ordersService.AddProductToOrder(new AddProductToOrderRequest(request.OrderId, request.UserId, request.ProductId));

            if (!response.IsSuccess)
            {
                return(BadRequest());
            }

            var order = response.Result.MapToResponse(_linkGenerator, HttpContext);

            return(Created(order.Link, order));
        }
        public IActionResult Order(OrderInputModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Redirect("/"));
            }

            string productId = productsService.GetProductByName(model.Product);

            if (productId == null)
            {
                return(Redirect("/"));
            }

            ordersService.AddProductToOrder(model.OrderId, productId);
            return(Redirect("/"));
        }
Ejemplo n.º 3
0
        public IActionResult AddToCart(int productId, int quantity)
        {
            OrderDetail orderDetail = new OrderDetail();

            orderDetail.OrderId   = _ordersService.GetActive(ContextHelper.GetCurrentUser(HttpContext).Id).Id;
            orderDetail.ProductId = productId;
            orderDetail.Quantity  = quantity;
            _logger.LogInformation("Quantity: " + quantity + ", Active order ID: " + orderDetail.OrderId);
            Product product = _productsService.GetOne(productId);

            _logger.LogInformation("This added: " + product.Name);
            try
            {
                _ordersService.AddProductToOrder(orderDetail);
                return(Json(new { text = "Successfully added the item to the cart" }));
            }
            catch (Exception)
            {
                return(Json(new { text = "Item already in cart!" }));
                //throw;
            }
        }